document.getElementById("id") is null 错误解决
来源:互联网 发布:kali sql 注入点 扫描 编辑:程序博客网 时间:2024/05/21 12:54
错误原因:body还没有加载,此时,无法获取dom对象元素,则程序就会报错document.getElementById("myHeader") is null
<html>
<head><title>我的测试文件</title>
<meta http-equiv="content-Type" content="text/html;charset=UTF-8"/>
<script type="text/javascript">
var x=document.getElementById("myHeader");
alert(x.innerHTML);
</script>
<body>
<h1 id="myHeader" onclick="getValue()">这是标题</h1>
<p>点击标题,会提示出它的值。</p>
</body>
</html>
解决办法就是办javascript代码写到body的元素的最后位置
<html>
<head><title>我的测试文件</title>
<meta http-equiv="content-Type" content="text/html;charset=UTF-8"/>
<body>
<h1 id="myHeader" onclick="getValue()">这是标题</h1>
<p>点击标题,会提示出它的值。</p>
<script type="text/javascript">
var x=document.getElementById("myHeader");
alert(x.innerHTML);
</script>
</body>
</html>
- document.getElementById("id") is null 错误解决
- TypeError document.getElementById(...) is null错误原因
- document.getElementById(...) is null
- TypeError: document.getElementById(...) is null
- document.getElementById得到null
- document.getElementById(id)
- $('#id')与document.getElementById( id )
- 如果ID不存在document.getElementById
- Firefox 下document.getElementById("ID") has no properties 或者为null
- function $(id){return document.getElementById(id)}说明
- document.getelementbyid('id') 和 $('#id')的区别
- $("#id") 和 document.getElementById('id')的区别
- $("#id")与document.getElementById("id")的区别
- $("#id")与document.getElementById("id")的区别
- document.getElementById("id").onclick=tt
- document.getElementById(id)的隐藏与显示
- document.getElementById("id").style.color="#000000"
- 关于document.getElementById(id)获取不到元素
- 四叉树与八叉树
- 社会化购物:Pinterest,Fancy还是美丽说,蘑菇街?
- nginx源码分析-ngx_cycle_s结构说明
- perl package和module
- Silverlight项目加载问题 无法读取项目文件“SL1201.csproj”。
- document.getElementById("id") is null 错误解决
- linux 牛人推荐书籍
- Web Service简介
- 【木头Cocos2d-x 003】Win7 64位系统搭建cocos2d-x环境并创建Android项目
- 网站分析的烦恼连载(活用篇上)
- 流年轻弹、离殇一曲
- Android.mk 文档规范
- perl基本语法介绍
- WebService中的方法是否允许重载