為啥以下網頁不能正常執行呢?

來源:互聯網
上載者:User

標籤: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

 

為啥以下網頁不能正常執行呢?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.