使用jquery捕获给定元素的所有事件(单击,更改,onmouseover,e.t.c) [英] Capture all events (click, change, onmouseover, e.t.c) for a given element using jquery

查看:74
本文介绍了使用jquery捕获给定元素的所有事件(单击,更改,onmouseover,e.t.c)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何,我是否可以检查现有元素是否附加了事件处理程序?假设一个简单的javascript方法将click事件添加到某个div.example(sans jquery),所以没有属性标记,那么可以使用jquery来捕获附加的事件吗?我尝试使用下面的代码完成此操作无效:

Is there anyway that I can check if an existing element has event handlers attached to it? Suppose a simple javascript method adds a click event to some div.example (sans jquery), so there are not attribute tags, is it possible to then, using jquery, to capture the event that was attached? I tried to accomplish this using the code below to no avail:

$( '.example' ).each( function() {
var newObj = $(this);
$.each($(newObj).data("events"), function(i, event) {
    alert(i);
        $.each(event, function(j, h) {
            alert(h.handler);
        });
});

});

推荐答案

试试这个

$( '#elm1' ).each( function() {

 $.each($(this).data("events"), function(i, event) {
        alert(i);
        $.each(event, function(j, h) {
            alert(h.handler);
        });
 });
});

这篇关于使用jquery捕获给定元素的所有事件(单击,更改,onmouseover,e.t.c)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆