我如何“重新绑定"?unbind('click') 后的点击事件? [英] How do I "rebind" the click event after unbind('click')?
问题描述
我有一个锚标签 next</a>
做成了一个按钮".有时,如果没有新内容可显示,则需要隐藏此标签.如果我只是用 .hide() 隐藏按钮并用 .show() 重新显示它,一切都很好.但我想改用 .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.
我遇到的问题是,如果用户在淡出动画期间单击按钮,可能会导致我运行节目的逻辑出现问题.我找到的解决方案是在原来的点击功能开始后,将点击事件与按钮解除绑定,等动画完成后再重新绑定.
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');
}
上面例子的最后一部分不起作用.点击事件实际上并没有重新绑定到锚点.有谁知道实现这一目标的正确方法?
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 人,所以像 unbind() 和 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
}
});
这篇关于我如何“重新绑定"?unbind('click') 后的点击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!