【问题标题】:event is not defined using Firefox [duplicate]未使用 Firefox 定义事件 [重复]
【发布时间】:2023-04-09 17:48:01
【问题描述】:

我想在单击按钮时显示一个框,并在我单击该框时隐藏它。

我所做的代码在 Chrome 和 IE 中有效,但在 Firefox 中无效(我只在这三个浏览器中测试过)。 Firefox 控制台显示ReferenceError: event is not defined

  • $('.button.open_login .bb')按钮
  • $('.button.open_login .panel_opened')面板

代码:

$(document).click(function(){
    if(!$(event.target).closest('.button.open_login .panel_opened').length) {
        if (site.ui.other.loginbox.is(":visible")){
            site.ui.other.loginbox.fadeOut(150);
        }
        else {
            if ($(event.target).closest('.button.open_login .bb').length){
                site.ui.other.loginbox.fadeIn(150);
            }
        }
    }
});

谢谢

【问题讨论】:

  • 你试过$(document).click(function(event){吗?
  • 您应该引用作为事件处理函数的参数传递的事件对象。全局 Event 对象已被弃用,并且不适用于所有浏览器。
  • @j08691 ...我很惭愧。如果您愿意,可以将其发布为答案。它可能对像我这样分心的人有用。谢谢

标签: javascript jquery


【解决方案1】:

要引用元素被点击的事件,你应该给点击函数传递一个参数,比如:

$(document).click(function(event){

【讨论】:

    猜你喜欢
    • 2013-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-19
    • 2012-12-03
    相关资源
    最近更新 更多