js放的位置不對,獲取的數據也是不一樣的~~~
<!doctype?html> <html> <head> <meta?charset="utf-8"> <title>無標題文檔</title> </head> <body> <p?id="con">javascript</p> <script?type="text/javascript"> var?mycar=?document.getElementById("con"); document.write("結果是:"+mycar); </script> </body> </html>
<!doctype?html> <html> <head> <meta?charset="utf-8"> <title>無標題文檔</title> <script?type="text/javascript"> var?mycar=?document.getElementById("con"); document.write("結果是:"+mycar); </script> </head> <body> <p?id="con">javascript</p> </body> </html>
各位大神幫忙解釋下是什么愿意呢~~~謝謝哦~~~
2015-01-06
頁面是順序加載的,當加載script的時候,body中的內容還沒加載,這個時候獲取就是null