getElementById
返回undefined。當我在Dom被加載後運行它。加載dom後getElementById返回undefined
這是我現在的代碼。我也嘗試從控制檯窗口運行該功能。
我試着在正文中調用window.onload
的功能。
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script>
function test() {
var element = getElementById("testing");
element.innerHTML+= "<br/>Yeah!";
}
</script>
</head>
<body>
<p id="testing">
I JUST love to test!
</p>
<script>window.onload=test();</script>
</body>
</html>
不應該是'document.getElementById(...)'? – Harry
是啊,先忘了文檔.. – user2013498
'document.getElementById' * never * returns'undefined'。 DOM元素或null。 – Bergi