[英]jquery: Cant unbind hover event?
My continue button has a hover event that tells you why it's disabled. 我的继续按钮有一个悬停事件,告诉您为什么禁用它。 The only problem is I can't remove the hover event when I enable the button....
唯一的问题是启用按钮时我无法删除悬停事件。
this works 这有效
function disable_continue_button(){
$('#frame_2 > .next')
.addClass('faded tt')
.hover(function(){
$hovered = $(this);
//tooltip?
tip = $('.tip.notification.information');
tip.find('div').html($hovered.attr('tt'));
tip.fadeIn(150);
},
function() {
tip.hide();
})
.mousemove(function(e) {
var mousex = e.pageX +40; //Get X coodrinates
var mousey = e.pageY -20; //Get Y coordinates
tip.css({top: mousey, left: mousex });
});
}
this doesn't work 这不起作用
function enable_continue_button(){
$('#frame_2 > .next')
.unbind('mouseenter mouseleave mousemove')
.removeClass('faded tt');
}
the classes are removed ok, but the hover tooltip is not removed... 可以删除这些类,但不会删除悬停工具提示...
Try unbinding mouseenter, mouseleave, mouseover and mouseout. 尝试解除绑定mouseenter,mouseleave,mouseover和mouseout。
$('#frame_2 > .next').unbind('mouseenter mouseleave mouseover mouseout');
EDIT: 编辑:
Unbinding just mouseenter and mouseleave is sufficient. 仅绑定mouseenter和mouseleave就足够了。
Here's an example to show it working. 这是一个示例 ,说明它可以正常工作。 When the above 4 events are unbound, the tooltip functionality is removed.
当上述4个事件解除绑定时,工具提示功能将被删除。
.hover(fnEnter, fnLeave)
is essentially shorthand for .mouseenter(fnEnter).mouseleave(fnLeave)
. .hover(fnEnter, fnLeave)
本质上是.mouseenter(fnEnter).mouseleave(fnLeave)
简写。
Since not all browsers support these two events natively, (if I recall correctly, only IE does), mouseenter()
maps to mouseover()
and mouseleave()
maps to mouseout()
, with some additional logic in each case to emulate the events. 由于并非所有浏览器都本机支持这两个事件(如果我没记错的话,只有IE支持),所以
mouseenter()
映射到mouseover()
, mouseleave()
映射到mouseout()
,每种情况下都有一些附加的逻辑来模拟事件。
This related question may help you unbind everything, and then you could rebind what you need? 这个相关的问题可能会帮助您取消绑定所有内容,然后可以重新绑定所需的内容? how to unbind all event using jquery
如何使用jQuery取消绑定所有事件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.