jquery:无法取消绑定悬停事件?

发布于 2024-10-16 03:32:01 字数 973 浏览 2 评论 0原文

我的继续按钮有一个悬停事件,可以告诉您它被禁用的原因。唯一的问题是,当我启用按钮时,我无法删除悬停事件......

这有效

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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泪眸﹌ 2024-10-23 03:32:01

尝试解除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(),在每种情况下都有一些附加逻辑来模拟事件。

Try unbinding mouseenter, mouseleave, mouseover and mouseout.

$('#frame_2 > .next').unbind('mouseenter mouseleave mouseover 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 to mouseover() and mouseleave() maps to mouseout(), with some additional logic in each case to emulate the events.

冷清清 2024-10-23 03:32:01

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

This related question may help you unbind everything, and then you could rebind what you need? how to unbind all event using jquery

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文