Uncaught TypeError: Cannot read property 'addEventListener'

版权声明:未经允许,请勿盗用 https://blog.csdn.net/qq_37916164/article/details/84343031

"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');
        });
    }

猜你喜欢

转载自blog.csdn.net/qq_37916164/article/details/84343031