$(‘body’).click(function(){ alert(‘test’ )})
var foo = $.data( $('body').get(0), 'events' ).click
// you can query $.data( object, 'events' ) and get an object back, then see what events are attached to it.
$.each( foo, function(i,o) {
alert(i) // guid of the event
alert(o) // the function deFinition of the event handler
});
您可以通过将对象引用(虽然不是jQuery对象)馈送到$.data进行检查,并为第二个参数馈送“事件”,这将返回一个填充有所有事件(例如“点击”)的对象。您可以遍历该对象并查看事件处理程序的作用。