jquery:无法取消绑定悬停事件?
我的继续按钮有一个悬停事件,可以告诉您它被禁用的原因。唯一的问题是,当我启用按钮时,我无法删除悬停事件......
这有效
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 });
});
}
这不起作用
function enable_continue_button(){
$('#frame_2 > .next')
.unbind('mouseenter mouseleave mousemove')
.removeClass('faded tt');
}
类被删除了,但是悬停工具提示未删除...
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试解除mouseenter、mouseleave、mouseover和mouseout的绑定。
编辑:
仅解除 mouseenter 和 mouseleave 的绑定就足够了。
这是示例来展示它的工作原理。当以上4个事件解除绑定后,工具提示功能将被移除。
.hover(fnEnter, fnLeave)
本质上是.mouseenter(fnEnter).mouseleave(fnLeave)
的简写。由于并非所有浏览器本身都支持这两个事件(如果我没记错的话,只有 IE 支持),
mouseenter()
映射到mouseover()
和mouseleave()
映射到mouseout()
,在每种情况下都有一些附加逻辑来模拟事件。Try unbinding mouseenter, mouseleave, mouseover and mouseout.
EDIT:
Unbinding just mouseenter and mouseleave is sufficient.
Here's an example to show it working. When the above 4 events are unbound, the tooltip functionality is removed.
.hover(fnEnter, fnLeave)
is essentially shorthand for.mouseenter(fnEnter).mouseleave(fnLeave)
.Since not all browsers support these two events natively, (if I recall correctly, only IE does),
mouseenter()
maps tomouseover()
andmouseleave()
maps tomouseout()
, with some additional logic in each case to emulate the events.这个相关的问题可能会帮助您解除所有内容的绑定,然后您可以重新绑定您需要的内容? 如何使用jquery解除所有事件的绑定
This related question may help you unbind everything, and then you could rebind what you need? how to unbind all event using jquery