JQuery:如何查看元素上定义的事件?

时间:2023-02-01 07:16:38

I use

$(window).bind( ... )

to set up event handlers, but for some reason I keep losing event handlers (i think). Is there any way when debugging (firebug) to see which custom events have been added to a given element?

设置事件处理程序,但由于某种原因,我一直在丢失事件处理程序(我认为)。调试(firebug)时是否有任何方法可以查看哪些自定义事件已添加到给定元素?

Yours Andreas

1 个解决方案

#1


All events bound by jQuery (e.g not inline events) can be accessed through .data

可以通过.data访问由jQuery绑定的所有事件(例如,不是内联事件)

var $el = $('#someId');
var allEvents =  $.data( $el , "events" );

or

$('#someId').data('events');

its very rare I bind events to the window object but the same notion should still apply so try $(window).data('events')

它非常罕见我将事件绑定到窗口对象,但同样的概念应该仍然适用所以尝试$(window).data('events')

This does indeed work demo here (writes to console so use firefox + firebug)

这确实在这里工作演示(写入控制台所以使用firefox + firebug)

#1


All events bound by jQuery (e.g not inline events) can be accessed through .data

可以通过.data访问由jQuery绑定的所有事件(例如,不是内联事件)

var $el = $('#someId');
var allEvents =  $.data( $el , "events" );

or

$('#someId').data('events');

its very rare I bind events to the window object but the same notion should still apply so try $(window).data('events')

它非常罕见我将事件绑定到窗口对象,但同样的概念应该仍然适用所以尝试$(window).data('events')

This does indeed work demo here (writes to console so use firefox + firebug)

这确实在这里工作演示(写入控制台所以使用firefox + firebug)