可能的原因是什么document.getElementById,$("#id")或者任何其他DOM方法/ jQuery选择器没有找到元素?
示例问题包括:
.val(),.html(),.text())返回undefined返回的标准DOM方法null导致以下任何错误:
未捕获的TypeError:无法设置null的属性'...'未捕获的TypeError:无法读取null的属性'...'
最常见的形式是:
未捕获的TypeError:无法设置null的属性'onclick'
未捕获的TypeError:无法读取null的属性"addEventListener"
未捕获的TypeError:无法读取null的属性'style'
我试图使用javascript填充div标签与名称字段中输入的内容(下面的示例).我不确定我做错了什么,但它不起作用,我不知道为什么不呢?我想要的只是当用户输入下面显示的名字时.我看过其他例子,但仍然困惑为什么这个例子不起作用.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4 /strict.dtd">
<html lang="en-GB">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>hello whirled</title>
<script type="text/javascript">
document.getElementById("name").onkeyup = function() {
document.getElementById("display").innerHTML = this.value;
}
</script>
</head>
<body>
<h1>
Bla Bla
</h1>
<form method="get" action=" ">
<p>
Other Text goes here
</p>
<p>
Type your first name here:
<input type="text" id="name" value="">
</p>
<div id="display">'s ball is not in the ball park.</div>
<noscript>
<div>
If you can see this then SCRIPTS are turned OFF on your machine …Run Code Online (Sandbox Code Playgroud)