Mozilla Firefox表示未定义Referenceerror事件,没有任何解决方案有效

Mozilla Firefox says Referenceerror event is not defined, no solution has worked

本文关键字:任何 解决方案 有效 事件 Firefox 表示 未定义 Referenceerror Mozilla      更新时间:2023-09-26

我的代码一直遇到问题。我已经搜索并找到了几种解决方案,但没有一个能解决问题。问题是 Mozilla Firefox 给了我一个错误:事件是点头定义的。其他浏览器工作正常。我的HTML代码调用函数:

var demoMap = '<table class="popup" onclick="closePopup(this)"><tr><td>';

和JavaScript

function closePopup(e) {
   if ( $(event.target).closest("#map").get(0) == null ) {    
        $(e).fadeOut(500, function () {
            $(e).remove();
        });
    }
}

定义event。您应该将$(event.target)更改为 $(e.target)

更多 - 你不应该在你的代码中使用内联JavaScript。我的解决方案是重写您的代码,使其如下所示:

var demoMap = '<table class="popup"><tr><td>; // Why HTML string in JS?

JS的其余部分:

$('table.popup').on('click', closePopup);
function closePopup(e) {
    var $this = $(this);
    if ( $this.closest("#map").get(0) == null ) {    
        $this.fadeOut(500, function () {
            $this.remove();
        });
    }
}
相关文章: