是否可以获取绑定到jQuery元素的事件列表? [英] Is it possible to obtain a list of events bound to an element in jQuery?
问题描述
正如问题所述,我需要绑定到特定元素的事件列表。
我的意思是像点击,鼠标悬停等事件绑定到该元素的加载的
(愚蠢)示例:
$( #element)。click(function()
{
// stuff
});
$(#element)。mouseover(function()
{
// stuff
});
$(#element)。focus(function()
{
// stuff
});
结果:
点击
mouseover,
focus
每个事件都添加到数组中。
可以使用jQuery数据方法访问此数组:
$(#element)。 data('events')
要将一个对象的所有事件记录到fireBug,只需键入:
console.log($(#element)。data('events'))
您将获得所有绑定事件的列表。
更新:
对于 jQuery 1.8 和更高版本,您必须查看内部的jQuery数据对象:
$($($($($))$($ ;//或
console.log($ ._ data($(#element)[0])。
As the question said, i need the list of events bound to a specific element.
I mean events like click, mouseover etc bound to that element at the loading of the dom.
(Stupid) example:
$("#element").click(function()
{
//stuff
});
$("#element").mouseover(function()
{
//stuff
});
$("#element").focus(function()
{
//stuff
});
Result:
click, mouseover, focus
Every event is added to an array.
This array can be accessed using the jQuery data method:
$("#element").data('events')
To log all events of one object to fireBug just type:
console.log ( $("#element").data('events') )
And you will get a list of all bound events.
Update:
For jQuery 1.8 and higher you have to look into the internal jQuery data object:
$("#element").each(function(){console.log($._data(this).events);});
// or
console.log($._data($("#element")[0]).events);
这篇关于是否可以获取绑定到jQuery元素的事件列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!