在JQuery中自动取消绑定事件处理程序 [英] Automatically unbind event handlers in JQuery

查看:73
本文介绍了在JQuery中自动取消绑定事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能对JQuery说,嘿!在添加这个事件之前取消绑定任何事件处理程序,而不显式调用unbind?。

Is it possible to say to JQuery, hey! unbind any event handlers before adding this one, without making an explicit call to unbind?.

类似

$("jq selector").click(function() { ...}, true);

其中,true表示我想取消绑定设置为元素的所有点击处理程序。
我在各种场合遇到过这种情况,有些人因为没有首先解开事件处理程序而有奇怪的行为。

Where true means I want to unbind all click handlers set to the element. I've came across this on various occasions and on some had strange behaviours due not unbinding event handlers first.

谢谢。

推荐答案

使用 unbind 方法

$("jq selector").unbind('click');

如果要删除与元素关联的所有事件,请调用unbind(),不带参数将删除附加到元素的所有处理程序:

If you want to remove all events associated with an element, Call unbind() with no argument and it will removes all handlers attached to the element(s):

$("jq selector").unbind();

这篇关于在JQuery中自动取消绑定事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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