如何在 jQuery 中检查元素上是否存在 onClick?

jqueryweb developmentfront end technology

这些代码可能会对你有所帮助 −

$('body').click(function(){ alert('test' )})

var foo = $.data( $('body').get(0), 'events' ).click
// 你可以查询 $.data( object, 'events' ) 并返回一个对象,然后查看它附加了哪些事件。
 $.each( foo, function(i,o) {
    alert(i) // 事件的 GUID
    alert(o) // 事件处理程序的函数定义
});

相关文章