jQuery 查找使用对象注册的事件处理程序 [英] jQuery find events handlers registered with an object
问题描述
我需要找出在对象上注册了哪些事件处理程序.
I need to find which event handlers are registered over an object.
例如:
$("#el").click(function() {...});
$("#el").mouseover(function() {...});
$("#el")
已注册点击和鼠标悬停.
是否有一个函数可以找出并可能遍历事件处理程序?
Is there a function to find out that, and possibly iterate over the event handlers?
如果通过适当的方法无法在 jQuery 对象上实现,那么在普通 DOM 对象上是否可能?
If it is not possible on a jQuery object through proper methods, is it possible on a plain DOM object?
推荐答案
从 jQuery 1.8 开始,事件数据不再可从数据的公共 API"获得.阅读这篇 jQuery 博文.您现在应该改用它:
As of jQuery 1.8, the event data is no longer available from the "public API" for data. Read this jQuery blog post. You should now use this instead:
jQuery._data( elem, "events" );
elem
应该是一个 HTML 元素,而不是一个 jQuery 对象或选择器.
elem
should be an HTML Element, not a jQuery object, or selector.
请注意,这是一个内部的私有"结构,不应修改.仅用于调试目的.
Please note, that this is an internal, 'private' structure, and shouldn't be modified. Use this for debugging purposes only.
在旧版本的 jQuery 中,您可能必须使用旧方法,即:
In older versions of jQuery, you might have to use the old method which is:
jQuery( elem ).data( "events" );
这篇关于jQuery 查找使用对象注册的事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!