2010-04-29 49 views
5

我发现一个网站,其中有一些我需要的功能,在JavaScript中。它使用jQuery,当我点击一个标签时,一些函数被执行,所以jQuery为标签设置了一个绑定。但是我怎样才能找出哪个函数与它绑定?萤火虫没有拿出来给我:(如何查看哪个jQuery函数绑定到元素?

回答

9

如果你想要说看到一个元素click事件处理程序,你会得到的第一个处理程序是这样的:

$("#element").data("events").click[0].handler 

这将使你的。功能运行Here's an example page showing that

下面是一个例子:

$("a").click(function() { 
    alert($("a").data("events").click[0].handler); 
});​ 

在点击,这将提醒:function() { alert($("a").data("events").click[0].handler); }

这只是使用click的一个示例,但无论您需要它用于作品,mouseenterfocus,无论事件可能是什么,包括自定义事件。

顺便说一句,如果你在一个元素或集合中的所有事件处理程序要循环,这会工作,只是选择更改为你以后(here's the same example updated to include this):

$.each($("a").data("events"), function(i, e) { 
    $.each(e, function(j, h) { 
    alert('Event: ' + i + '\nHandler:\n' + h.handler); 
    }); 
}); 

+0

+1优秀的答案。 – 2010-04-29 23:54:03

+0

非常敏捷的方法,谢谢! – teMkaa 2010-04-30 09:00:10

1

您是否尝试过使用FireQuery?应该安装在每个人的Firefox/Firebug安装程序中。

相关问题