如果菜单已经打开,如何使用Jquery阻止fadeOut触发?

时间:2010-09-01 12:06:44

标签: jquery

如果菜单已经打开,我不确定为什么我的代码会触发fadeOut()效果?请参阅以下代码:

$('.rtmenu').click(function(e) { e.stopPropagation(); });

$('.rtmenu').mouseout(function(){ 
     $(document).one('click',function() { $('.rtmenu').fadeOut(200); }); 
 })

非常感谢任何帮助

1 个答案:

答案 0 :(得分:0)

如果代码位于document.ready内并且.rtmenu元素未动态创建,则您应该使用该代码。 You can test it here

如果它们是动态创建的,请使用.live()处理程序和.stopImmediatePropagation()稍微更改一下,如下所示:

$('.rtmenu').live('click', function(e) { e.stopImmediatePropagation(); });
$(document).click(function() { $('.rtmenu').fadeOut(200); });​

You can give it a try here