PDA

View Full Version : how can i get the parameter from the html?



joshokn
21 Apr 2007, 12:18 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>

<SCRIPT LANGUAGE="JavaScript" src="jquery.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" id="script" src='js/script.js?name="xxx"&sex="male"'></SCRIPT>
</HEAD>

<BODY>
<SCRIPT LANGUAGE="JavaScript">
alert($("#script").attr("src").split("?")[1]);
alert($("script[@id=script]").attr("src").split("?")[1]);
</SCRIPT>
</BODY>
</HTML>


How can i get the 'name' and 'sex' in script.js?

One soulation is use jquery.js, but i don't like to import this library.Is there any api in ext that can repalce this?

Animal
21 Apr 2007, 2:11 AM
<SCRIPT LANGUAGE="JavaScript" id="script" src='js/script.js?name="xxx"&sex="male"'></SCRIPT>


If js/script.js is a static file (And not a scripted resource on the server), then... well... what the hell are you on about? Queries on a static URL won't be processed - what's supposed to process them?

If the page generating script which generates that page knows the values, just write out a javascript assignment statement to put the values into variables.



<SCRIPT LANGUAGE="JavaScript">
alert($("#script").attr("src").split("?")[1]);
alert($("script[@id=script]").attr("src").split("?")[1]);
</SCRIPT>


Why are you going through all this?

joshokn
22 Apr 2007, 10:03 PM
It's my fault , i just can


script = 'document.getElementById('script')';
src = script.getAttribute('src');
...

Sorry.

Animal
22 Apr 2007, 11:41 PM
Why would you do that? At page generation time, you know the src of the script (because you write it out to the browser when you write out the <script> tag), so just use that value directly when writing out the javascript code.