Jump to content


  • Posts

  • Joined

  • Last visited

hvw3347's Achievements


Newbie (1/7)



  1. total 3 files --#1. js2.htm:<html> <head> <title>js-in-js test</title> <script type="text/javascript" src="b.js"> </script> </head> <body onload="add_script()"> <input type="button" onclick="disp_alert('Alert 1')" value="Display alert box 1" /> </body></html>#2 a.js:function disp_alert(txt){ alert(txt)}#3 b.js:function add_script(){ head = document.getElementsByTagName('head')[0]; e = document.createElement('script'); // create a script element e.type = 'text/javascript'; // set the type of the script e.src = 'a.js'; // point the script tag at your js file head.appendChild(e);}The above b.js works well. The following b.js does not work:function add_script(){ document.getElementById("thebody").innerHTML += "<scr" + "ipt type=\"text/javascript\" src=\"a.js\"></scr" + "ipt>";}The web page's status bar shows: "Done, but with error on page". What is wrong?
  2. The code with ... e.src = 'a.js'; head.appendChild(e); ...works just fine. However, the last code still does not work when I try. Does it depend on the server? I have IIS 6. Thanks a lot! At least, I've got one that works.Harvey
  3. I have some troubles when using your code. If the code is:<body id="thebody"><script type="text/javascript"> document.getElementById("thebody").innerHTML += "<script type=\"text/javascript\" src=\"a.js\"></script>"</script><input type="button" onclick="disp_alert('Alert 1')" value="Display alert box 1" /></body>The page displayes as:" then, the-button [Display alert box 1]Why is " shown up? the button still does not work. Did I do anything wrong? Thanks!
  4. Hi,I try to include a javascript in another javascript, but it does not work. Below is my code, all 3 files are in the same folder. Please help to indicate the error:a.js:function disp_alert(txt){ alert(txt)}b.js:document.write('<script type="text/javascript" src="' + a.js + '"></script>'); test_js_in_js.htm:<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Test js in js</title><script language="JavaScript" type="text/javascript" src="b.js"> </script ></head><body><input type="button" onclick="disp_alert('Alert 1')" value="Click me to display alert box 1" /></body></html>When I click the button, it does not show alert. If I replace b.js with a.js in the htm file, then it works. What is wrong? in b.js or in the htm file?Thanks for help!Harvey
  5. Hi,I just started learning asp.net and found the ASP.NET Tutorial at this w3school web site very helpful. It provides all real codes for all topics. However, when I reached the topic "ASP.NET 2.0 - Navigation" that has a real sample "Click here to see a demo of Menu, TreeView, and SiteMapPath", I see only part of codes. I don't know how to put them together. Can somebody tell me where to get the whole codes? I appreciate all the help!Harvey
  • Create New...