我已经成功地使用了document.GetElementById()
,但从一段时间开始,我就不能再让它工作了。请看下面的代码:
<html>
<head>
<title>no title</title>
<script type="text/javascript">
document.getElementById("ThisWillBeNull").innerHTML = "Why is this null?";
</script>
</head>
<body>
<div id="ThisWillBeNull"></div>
</body>
</html>
我现在一直都在使用document.getElementById("parsedOutput") is null
。无论我使用的是火狐还是Chrome,或者我启用了哪些扩展,或者我使用了什么头文件,都是null
,我找不到可能的错误所在。
发布于 2010-04-14 02:34:41
您可以像这样使用脚本标记:
<script defer>
// your JavaScript code goes here
</script>
加载完所有内容后,JavaScript将应用于所有元素。
发布于 2010-04-14 02:35:40
试试这个:
<script type="text/javascript">
window.onload = function() {
document.getElementById("ThisWillBeNull").innerHTML = "Why is this null?";
}
</script>
发布于 2010-04-14 02:34:24
https://stackoverflow.com/questions/2632137
复制相似问题