您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

检查元素上是否存在事件

检查元素上是否存在事件

$(‘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进行检查,并为第二个参数馈送“事件”,这将返回一个填充有所有事件(例如“点击”)的对象。您可以遍历该对象并查看事件处理程序的作用。

其他 2022/1/1 18:13:42 有571人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶