【JavaScript】页面加载 解决Uncaught TypeError: Cannot set property of undefined at
来源:互联网 发布:理肤泉b5真假知乎 编辑:程序博客网 时间:2024/06/03 20:26
在初学js的时候,有同学会遇到
Uncaught TypeError: Cannot set property 'onmouseover' of undefinedat **.html
的问题
这个问题牵扯到页面加载顺序的问题。
我们知道 页面的加载顺序(正确的顺序)是
结构>样式>行为 也就是 html>css>JavaScript
如果我们的js部分写到了页面内容的前面,那么在加载的时候,浏览器的加载顺序(错误顺序)是js>html,所以 我们在js中获取的html元素就出现了undefined的错误。
因为没有加载html的时候,js的执行对象找不到。
解决方法:
1.把js内容提到页面内容之后,也就是说 你的</script>标签要紧挨着</body>标签 2.把所有的js代码用 window.onload=function(){ (这里写代码) }; 包起来即可。
阅读全文
0 0
- 【JavaScript】页面加载 解决Uncaught TypeError: Cannot set property of undefined at
- Uncaught TypeError: Cannot set property 'applyDefaults' of undefined
- Uncaught TypeError: Cannot set property 'mobile' of undefined
- Uncaught TypeError: Cannot set property '0' of undefined 关于JavaScript多维数组
- Uncaught TypeError: Cannot set property ' ' of null 错误解决
- javascript中,Uncaught TypeError: Cannot set property 'onchange' of null错误解决
- TypeError: Cannot set property 'user' of undefined
- jquery.mobile-1.4.5.min.js:3 Uncaught TypeError: Cannot set property 'mobile' of undefined
- js遇到的Uncaught TypeError: Cannot set property 'onclick' of null at HTMLButtonElement.add.onclick错
- Extjs4---Uncaught TypeError: Cannot read property ‘items’ of undefined
- 【StackFlow】Uncaught TypeError: Cannot read property 'pageCount' of undefined
- Ckeditor: Uncaught TypeError: Cannot read property 'keyCode' of undefined 解决方法
- Uncaught TypeError: Cannot read property 'msie' of undefined问题解决方案
- Uncaught TypeError: Cannot read property 'options' of undefined 错误
- Uncaught TypeError: Cannot read property 'length' of undefined
- 错误:Uncaught TypeError: Cannot read property 'WebSocket' of undefined
- Uncaught TypeError: Cannot read property 'value' of undefined
- Uncaught TypeError: Cannot read property 'plugin' of undefined
- Servlet--Cookie基础
- POJ2891 Strange Way to Express Integers(解多元线性同余方程)(中国剩余定理非互质版)(例题)
- JDBC基础学习总结
- 还是畅通工程(最小生成树&&并查集)
- 成员变量、类变量(静态变量)、局部变量的区别
- 【JavaScript】页面加载 解决Uncaught TypeError: Cannot set property of undefined at
- 无旋treap:从好奇到入门(例题:bzoj3224 普通平衡树)
- 今天课上所听的9种排序!
- 4.多线程之守护线程
- C++ STL Map的创建、删除、插入、更新、遍历
- 著名的show_space
- cglib动态代理
- Golang版Tensorflow安装记录
- leetcode之分治总结