你如何解除特定命名空间中的所有jQuery事件的绑定? [英] How would you unbind all jQuery events from a particular namespace?

查看:133
本文介绍了你如何解除特定命名空间中的所有jQuery事件的绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jQuery中是否有全局解除绑定功能,以便我能够从给定的命名空间中删除所有绑定的事件?例如:

Is there a "global" unbind function in jQuery, such that I'd be able to remove all bound events from a given namespace? eg:

// assume these are the events bound to different elements
$('#foo').bind('click.myNS', ...);
$('#bar').bind('keyup.myNS', ...);
$('#baz').bind('dblclick.myNS', ...);    

// magic occurs here...
$.magicalGlobalUnbindFunction('.myNS');

// ...and afterwards, the three binds from above are gone

我所看到的所有示例都取消绑定,需要先选择一些元素。我猜,在技术上,你可以做 $('*')。unbind('。myNS'),但这似乎非常效率低下。 / p>

All the examples I've seen for unbind require some elements to be selected first. I guess that technically, you could do $('*').unbind('.myNS'), but that seems very inefficient.

推荐答案

您可以将 myNS 添加为每个元素的类,你想取消绑定事件。

You could add myNS as a class to each of the elements where you want to unbind the events.

这篇关于你如何解除特定命名空间中的所有jQuery事件的绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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