列出元素的所有绑定(使用 jQuery) [英] List all bindings of an element (with jQuery)
问题描述
有没有办法列出 jQuery 元素上的所有绑定?jQuery 的 bind() 似乎只是附加了它们,我没有找到可以获取绑定的 jQuery 函数.
Is there a way to list all bindings on a jQuery element? jQuery's bind() does only seem to attach them and I didn't find a jQuery function that does get the bindings.
推荐答案
此答案适用于 jQuery 版本 <1.8
最好的方法,可能是 FireFox 的 FireQuery
插件.真是个好工具.
Best way to do that, probably the FireQuery
plugin for FireFox. Really a neat tool.
如果您想/需要完成代码中",请使用 jQuery .data('events')
对象.
If you want/need to accomplish that "in-code", use jQuerys .data('events')
object.
$.each($('#element').data('events'), function(i, e) {
console.log(i, e);
});
所有通过 jQuery 绑定的事件都会被推送到该对象中.当然,可能还有其他事件处理程序,例如 on
-anything,您必须明确检查.
All events that were bound via jQuery gets pushed into that object. Of course, there might also be other event handlers like on
-anything, for which you would have to check explicitly.
参考:FireQuery
这篇关于列出元素的所有绑定(使用 jQuery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!