有没有办法删除 jQuery 中的所有命名空间绑定?
我有一些简单的代码,例如:
$('#modal-buttons [href*=close]').bind('click.modalClose',function(){
app().modal('close')
});
但是假设我不知道 click.modalClose
将在任何地方绑定,有没有办法销毁所有这些特定的绑定,无论元素是什么,而不必这样做下列?
$('#modal-buttons [href*=close],.someOtherelement,#onemore,.another').unbind('click.modalClose');
I have some simple code like:
$('#modal-buttons [href*=close]').bind('click.modalClose',function(){
app().modal('close')
});
But let's say I wont know everywhere the click.modalClose
will be bound, is there a way to destroy all of those specific binds no matter what the element rather than having to do the following?
$('#modal-buttons [href*=close],.someOtherelement,#onemore,.another').unbind('click.modalClose');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要摆脱所有绑定,只需执行以下操作:
这将获得所有绑定。或者,您可以确保绑定始终通过您自己的 API 进行,然后您可以跟踪哪些元素实际受到影响。 (但是,如果您打算将处理程序与它们所绑定的所有元素解除绑定,我看不出有什么意义,除非您的页面规模很大并且
$('*')
事情花费的时间太长了。)To get rid of all bindings, just do:
That'll get all of them. Alternatively, you could make sure that the binding always happens via your own API, and then you can keep track of what elements are actually affected. (If you're going to unbind the handlers from all elements they're bound to, however, I don't see the point, unless your page is of epic proportions and the
$('*')
thing takes too long.)