我该如何与QUOT;重新绑定"后解除绑定click事件(“点击”)? [英] How do I "rebind" the click event after unbind('click')?

查看:269
本文介绍了我该如何与QUOT;重新绑定"后解除绑定click事件(“点击”)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个锚标记<一类=下一个>接下来< / A> 拍成一个按钮。有时候,这个标签需要,如果有什么新的显示被隐藏。与.show所有工作正常,如果我只是隐藏与.hide()和按钮重新显示出来()。但我想使用.fadeIn()和.fadeOut()代替。

I have an anchor tag <a class="next">next</a> made into a "button". Sometimes, this tag needs to be hidden if there is nothing new to show. All works fine if I simply hide the button with .hide() and re-display it with .show(). But I wanted to uses .fadeIn() and .fadeOut() instead.

我遇到的问题是,如果在淡出动画过程中用户点击按钮,它可以引起我已经运行显示的逻辑问题。我找到的解决方案是原来的点击功能开始后,从解除按钮的Click事件,然后在动画完成后重新绑定。

The problem I'm having is that if the user clicks on the button during the fadeOut animation, it can cause problems with the logic I have running the show. The solution I found was to unbind the click event from the button after the original click function begins, and then re-bind it after the animation is complete.

$('a.next').click(function() {
    $(this).unbind('click');
    ...
    // calls some functions, one of which fades out the a.next if needed
    ...
   $(this).bind('click');
}

上面的例子中的最后一部分不工作。 click事件实际上没有重新绑定到锚。没有人知道做到这一点的正确方法?

the last part of the above example does not work. The click event is not actually re-bound to the anchor. does anyone know the correct way to accomplish this?

我是一个自学成才的jQuery的家伙,所以有些像解除绑定()和bind()更高层次的东西超过我的头,jQuery的文档是不是真的很简单,我听不懂。

I'm a self-taught jquery guy, so some of the higher level things like unbind() and bind() are over my head, and the jquery documentation isn't really simple enough for me to understand.

推荐答案

我想补充一个检查,看看它的动画第一:

I would just add a check to see if it's animating first:

$('a.next').click(function() {
    if (!$(this).is(":animated")) {
        // do stuff
    }
});

这篇关于我该如何与QUOT;重新绑定&QUOT;后解除绑定click事件(“点击”)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆