2016-07-14 26 views
1

我想单击按钮时显示一个框,并在单击此框时将其隐藏。未使用Firefox定义事件

enter image description here

的代码我的确在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); 
      } 
     } 
    } 
}); 

谢谢

+5

你有没有试过'$(document).click(function(event){'? – j08691

+1

)你应该参考事件对象,我作为事件处理函数的参数传递。全局事件对象已被弃用,并且不适用于所有浏览器。 –

+0

@ j08691 ...我很惭愧。如果你想要,你可以把它作为答案。这对另一个像我这样分心的人可能会有用。谢谢 – nanilab

回答

1

可以指向被点击的元素的情况下,你应该通过参数来点击的功能,如:

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