且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

测试事件处理程序是否绑定到jQuery中的元素

更新时间:2023-10-06 23:24:58

您可以从数据缓存中获取此信息。

You can get this information from the data cache.

例如,将它们记录到控制台(firebug,ie8):

For example, log them to the console (firebug, ie8):

console.dir( $('#someElementId').data('events') );

或迭代它们:

jQuery.each($('#someElementId').data('events'), function(i, event){

    jQuery.each(event, function(i, handler){

        console.log( handler.toString() );

    });

});

另一种方法是使用以下 bookmarklet 但显然这在运行时没有帮助。

Another way is you can use the following bookmarklet but obviously this does not help at runtime.