Uncaught TypeError: Cannot read property 'addEventListener'
程序员文章站
2022-03-27 13:06:56
...
"Uncaught TypeError: Cannot read property ‘addEventListener’ of null"
标签元素还没有创建就调用引用标签的脚本就会出现此问题?
解决方式:
一.将脚本放置在脚本标签的后面 ;
二.判断id是否为null:
if(document.getElementById("id")!=null){
document.getElementById("id").addEventListener("tap", function () {
mui('#thailandTour').popover('toggle');
});
}
上一篇: 判断ios还是Android
下一篇: JS完美运动框架【利用了Json】
推荐阅读
-
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object
-
npm ERR! Cannot read property 'path' of null
-
js报错 Cannot read property 'getAttribute' of null
-
[VUE ERROR] Error in render: "TypeError: Cannot create property 'header' on boolean 'true'"
-
微信小程序报Cannot read property 'setData' of undefined的错误
-
webpack报错Cannot read property 'presetToOptions' of undefined
-
Extjs4---Uncaught TypeError: Cannot read property ‘items’ of undefined
-
JavaScript Uncaught TypeError: Cannot read property 'value' of null
-
Cannot read property 'tap' of undefined
-
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#