繁体   English   中英

jQuery:无法取消悬停事件?

[英]jquery: Cant unbind hover event?

我的继续按钮有一个悬停事件,告诉您为什么禁用它。 唯一的问题是启用按钮时我无法删除悬停事件。

这有效

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');    
}

可以删除这些类,但不会删除悬停工具提示...

尝试解除绑定mouseenter,mouseleave,mouseover和mouseout。

$('#frame_2 > .next').unbind('mouseenter mouseleave mouseover mouseout');

编辑:

仅绑定mouseenter和mouseleave就足够了。

这是一个示例 ,说明它可以正常工作。 当上述4个事件解除绑定时,工具提示功能将被删除。

.hover(fnEnter, fnLeave)本质上是.mouseenter(fnEnter).mouseleave(fnLeave)简写。

由于并非所有浏览器都本机支持这两个事件(如果我没记错的话,只有IE支持),所以mouseenter()映射到mouseover()mouseleave()映射到mouseout() ,每种情况下都有一些附加的逻辑来模拟事件。

这个相关的问题可能会帮助您取消绑定所有内容,然后可以重新绑定所需的内容? 如何使用jQuery取消绑定所有事件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM