為什么把js放到要執行元素的上面就會失敗,是不是也有執行順序的問題?
??<script?type="text/javascript"> ????document.write("hello"); ????document.getElementById("p1").style.color="blue"; ??</script> ?? ??<p?id="p1">我是第一段文字</p> ??<p?id="p2">我是第二段文字</p>
??<script?type="text/javascript"> ????document.write("hello"); ????document.getElementById("p1").style.color="blue"; ??</script> ?? ??<p?id="p1">我是第一段文字</p> ??<p?id="p2">我是第二段文字</p>
2015-04-17
舉報
2015-04-17
是的, 因為你的DOM樹還沒有加載完全, js就已經執行了。 如果你要寫在最上面,最好等onload 事件完成后執行