例如,我将以下函数与某个元素相关联
$('table#users tbody tr:first #save').click(function(){
$(this).closest('tr').remove();
});
现在,如果我不知道这个函数存储在哪里,有没有办法查看与click()代码相关联?在上面的例子中,我想要一种在firebug或其他方式中查看的方法
$(this).closest('tr').remove();
如果我在控制台中写作,我会得到一个指向dom检查员的链接
>>> ($('table#users tbody tr:first #save').click)
function()
但是链接是针对jquery库的,而不是我想要的代码。
答案 0 :(得分:2)
我认为这会回答你的问题How to find event listeners on a DOM node when debugging or from the JavaScript code?
您在编写代码时获得DOM检查器链接的原因是调用$(selector).click
实际上会引发单击事件并返回结果集。
答案 1 :(得分:1)
尝试使用Firebug的eventbug插件:http://blog.getfirebug.com/2009/10/30/event-listener-view-for-firebug/
答案 2 :(得分:1)
javascript中还有一个Function对象的默认方法 - toSource
http://www.devguru.com/technologies/ecmascript/quickref/function_object.html
示例:
>>> $( 'JQ-runCode')。click.toSource()
“(function(d){return d?this.bind(b,d):this.trigger(b);})”