当js文件放在head里面时,如果绑定了onclick或者onmouseover事件,就会出现如下图类似的错误,是因为浏览器的加载你写的html文档的顺序是从上往下,加载完按钮节点才执行的js,所以当浏览器自顶向下解析时,找不到onclick绑定的按钮节点,于是报错。解决办法有:第一,把js文件放在底部加载;第二,使用window.onload=function(){}包裹js内容。
相关文章
- 微信小程序报错(1) (in promise) MiniProgramError Cannot read property ‘findIndex‘ of null TypeError: Cannot
- Uncaught TypeError: Cannot set property 'innerHTML' of null
- echarts js报错 Cannot read property 'getAttribute' of null
- 【jQuery学习】用JavaScript写一个输出多选框的个数报错:Cannot set property 'onclick' of null"
- 在vue中使用echarts报错Cannot read property getAttribute of null
- 小程序分享报错 Cannot read property 'apply' of null;at page XXX onShareAppMessage function
- cannot set property ‘context’ of null
- JS弹窗重复弹出问题及解决Uncaught TypeError: Cannot set property ‘onclick‘ of null错误的方法
- 关于Uncaught TypeError: Cannot set property 'onClick' of null。的问题
- 在vue-cli中使用axios时报错TypeError: Cannot set property 'l