【发布时间】:2013-04-12 00:47:38
【问题描述】:
当同时触发一个事件时,我不知道如何解除一个事件与另一个事件的绑定。我有这种 html 层次结构:
<div class="first"></div>
<div class="second"></div>
当鼠标输入 .first 时,会显示 .second。然后,如果鼠标离开 .first,.second 应该隐藏,除非鼠标正在进入 .second。 所以,我的问题是同时触发了 $('.first').mouseleave() & $('.second').mouseenter() 。我尝试了这样的事情,但没有结果:
$('.first').mouseenter(function(){
$('.second').show();
});
$('.first').mouseleave(function(){
$('.second').hide();
});
$('.second').mouseenter(function(){
$('.first').unbind('mouseleave');
});
$('.second').mouseleave(function(){
$('.first').bind('mouseleave');
$('.second').hide();
});
有什么线索吗?
【问题讨论】:
-
您没有用于 .first.. 的 mouseenter?
标签: jquery mouseevent bind unbind