【发布时间】: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