English 中文(简体)
Jquery:在Mendu外被点击后,Mendu胜诉消失
原标题:Jquery: drop down menu wont disappear after clicking outside of menu

I m new to jquery and I m ook at google s Code to establish their More button. 我在晚上工作,但使这一下降消失的唯一途径是再次点击。 我是否可以增加改变这一方法,这样,在下降的菜单本身之外的任何点击都将关闭吗? 感谢见解!

http://jsfiddle.net/rKaPN/1/

最佳回答

Bind 一次点击事件,以抓获任何点击,将其藏匿起来。

$("html").click(function() {
  menu.find( .active ).removeClass( active );
});

Then override that on your menu s click event using .stopPropagation();

menu.find( ul li > a ).bind( click , function (event) {
  event.stopPropagation();

Fiddle: http://jsfiddle.net/rKaPN/12/

问题回答

你也可以补充这一点,因此用户不必点击。

$("body:not(.menu)").hover(function(){ $(".menu").find( .active ).removeClass( active );})

在开菜单时,制造了一种透明的超额电离窗户和高端。 点击了这块 d,关闭了菜单,销毁了零件。

如果你在布卢特事件发生时主动放弃,那么你会把一次模糊事件与具体的菜单捆绑在一起,而不是每点击html的dom子。 用以下几个字取代:

  //displaying the drop down menu
  $(this).parent().parent().find( .active ).removeClass( active );
  $(this).parent().addClass( active );

  //displaying the drop down menu
  $( .active ).removeClass( active );
  $(this).parent().addClass( active );
  $(this).blur(function() {
      $( .active ).removeClass( active );
  });




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签