標籤:style blog http io ar color os sp java
1.以下代碼
a) </head></script>順序寫反了,導致不能認識到有script
b)但還是執行不正常,為啥呢?
A:這裡建立了東西,但是沒有添加進去!
1 <head> 2 <script type="text/javascript"> 3 4 function f() 5 { 6 var c=document.createElement(‘a‘); 7 c.setAttribute("href","d[2].value"); 8 c.setAttribute("name","a1"); 9 c.setAttribute("class","b");10 c.innerHTML = "d[1].value";11 }12 </head>13 14 </script> 15 16 <body onload="f()">17 18 </body>View Code
2. 發現以下代碼img src="http://www.w3schools.com/jsref/w3javascript.gif" 裡面的圖片地址無效的話就會不能執行
<!DOCTYPE html><html><body onload="loadImage()" ><img src="http://www.w3schools.com/jsref/w3javascript.gif" onload="loadImage()" width="100" height="132"><script>function loadImage() { alert("Image is loaded");}</script></body></html>View Code
3. 以下代碼能執行,但是如果把document.getElementById("myDIV").appendChild(c);改成document.appendChild(c);就會出錯!
1 <head> 2 <script type="text/javascript"> 3 4 function f() 5 { 6 var c=document.createElement(‘a‘); 7 c.setAttribute("href","http://www.qq.com"); 8 c.setAttribute("name","a1"); 9 c.setAttribute("class","b");10 c.innerHTML = "http://www.qq.com";11 12 document.getElementById("myDIV").appendChild(c);13 }14 </script> 15 16 </head>17 18 19 20 <body onload="f()">21 <div id="myDIV"/>22 </body>View Code
為啥以下網頁不能正常執行呢?