jQuery解除绑定然后绑定 [英] JQuery Unbind and then bind
本文介绍了jQuery解除绑定然后绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经找到了很多与此主题相关的示例.但是,我并没有完全理解.我的逻辑看起来正确吗?我有一个div作为按钮(.myClass的类),除非myCount> = 1,否则我不希望它可单击.
I've found lots of examples on this topic.. however, I do not fully understand. Does my logic seem correct? I have a div as button (class of .myClass) and I don't want it clickable unless myCount >= 1.
// I want to unbind if myCount == 0
if ( myCount == 0) {
$('.myClass').unbind().css("opacity","0.5");
} else {
// **would this rebind?**
$('.myClass').click(callMyFunction);
}
推荐答案
您可以在on()
中使用命名空间事件. bind()
已被弃用.
You could use namespaced events, with on()
. bind()
has been deprecated.
var foo = function () { ... }
if (myCount)
$('.myclass').on('click.foo', foo)
else
$('.myclass').off('.foo')
这篇关于jQuery解除绑定然后绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文