错误:未捕获TypeError:无法设置属性'innerHTML'为null [英] error: Uncaught TypeError: Cannot set property 'innerHTML' of null

查看:194
本文介绍了错误:未捕获TypeError:无法设置属性'innerHTML'为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在chrome中运行该程序时,我继续收到错误未捕获TypeError:无法设置属性innerHTML为null。我现在不在做错事,任何帮助都不会感激。感谢高级。

 <!DOCTYPE html> 
< html>
< head>
< / head>
< script>
var x =hey;
var counter = 1;
var button = document.getElementById(button);
var div = document.getElementById(box);
var text = document.getElementById(text);
var sound = document.getElementById(sound);
var array = [感谢点击,继续点击,再一次点击,为什么你继续点击我,停止点击我!
function thing(file){
var y = array [Math.floor(Math.random()* array.length)];
if(x == y){
while(y == x){
var y = array [Math.floor(Math.random()* array.length)];
}
}
form1.text.value = y;

x = y;
sound.innerHTML =< embed src = \+ file +\hidden = \true\autostart = \true\loop = \false\ /> 中;

}
< / script>
< / head>
< body>
< form name =form1>
< input type =buttonid =buttonvalue =clickonClick =thing('sound.mp3')/>
< input type =textid =textvalue =hey/>
< / form>
< div id =sound>
< p>
< / p>
< / div>
< / body>
< / html>


解决方案

等待加载窗口:

  window.onload = function()
{
// yourJSCodeHERE
}

或在< / body> 标签之后移动您的JS。 / p>

I keep on getting the error "Uncaught TypeError: Cannot set property 'innerHTML' of null" when I try to run this program in chrome. I do not now what I am doing wrong, and and any help would be appreciated. Thanks in advanced.

<!DOCTYPE html>
<html>
<head>
</head>
<script>
    var x = "hey";
    var counter = 1;
    var button = document.getElementById("button");
    var div = document.getElementById("box");
    var text = document.getElementById("text");
    var sound = document.getElementById("sound");
    var array=[ "thanks for clicking", "keep on clicking", "click one more time", "why do you keep on clicking me?", "stop clicking me!"];
function thing(file){
    var y = array[Math.floor(Math.random() * array.length)];
        if (x == y){
            while (y == x){
                var y = array[Math.floor(Math.random() * array.length)];
        }   
        }
    form1.text.value=y;

    x = y;
sound.innerHTML = "<embed src=\""+file+"\"hidden=\"true\"autostart=\"true\" loop=\"false\"/>";

}
</script>
</head>
<body>
<form name="form1">
<input type="button" id="button" value="click" onClick="thing('sound.mp3')" />
    <input type="text" id="text" value="hey" />
</form>
<div id="sound">
<p>
</p>
</div>
</body>
</html>

解决方案

Wait for the window to load:

window.onload = function()
{
    //yourJSCodeHERE
}

or move your JS after the </body> tag.

这篇关于错误:未捕获TypeError:无法设置属性'innerHTML'为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆