<!DOCTYPE HTML>
<html>
<head>
<script>
document.write("TEST1")
document.getElementById("demo").innerHTML="TEST2"
document.write("TEST3")
</script>
</head>
<body>
<p id="demo">TO_BE_REPLACED</p>
</body>
</html>
這裏是輸出: TEST1javascript - 爲什麼不用innerHTML替換運行?
TO_BE_REPLACED
似乎執行已停在document.getElementById("demo").innerHTML="TEST2"
的JavaScript。爲什麼不執行?
看到這個:http://stackoverflow.com/questions/5704924/executing-javascript-in-the-head-getelementbyid-returns-null,http://stackoverflow.com/questions/8864776/getelementbyid -and-null-why,http://stackoverflow.com/questions/5371047/getelementbyid-returns-null-even-though-the-element-exists或http://stackoverflow.com/questions/10839271/null-return -by-getelementbyid-method-in-javascript – HoLyVieR 2013-02-19 02:45:21