检查任何DOM元素的附加事件处理程序 [英] Inspect attached event handlers for any DOM element

查看:80
本文介绍了检查任何DOM元素的附加事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法查看DOM元素的任何事件附加的函数/代码?使用Firebug或任何其他工具。

解决方案

使用传统的元素附加的事件处理程序element.onclick = code>或HTML < element onclick =handler> 可以从 element.onclick 属性从脚本或调试器中。



使用DOM Level 2事件附加的事件处理程序 addEventListener 方法和IE的 attachEvent 目前无法从脚本中检索。 DOM Level 3曾经提出 element.eventListenerList 来获取所有的监听器,但是不清楚这是否会使它成为最终规范。今天没有任何浏览器中没有实现。



作为浏览器扩展名的调试工具可以访问这些类型的监听器,但我没有意识到任何实际的。



一些JS框架留下足够的事件绑定记录来解决他们已经做了什么。 Visual Event 采用这种方法来发现通过几个流行框架注册的听众。 p>

Is there any way to view what functions / code are attached to any event for a DOM element? Using Firebug or any other tool.

解决方案

Event handlers attached using traditional element.onclick= handler or HTML <element onclick="handler"> can be retrieved trivially from the element.onclick property from script or in-debugger.

Event handlers attached using DOM Level 2 Events addEventListener methods and IE's attachEvent cannot currently be retrieved from script at all. DOM Level 3 once proposed element.eventListenerList to get all listeners, but it is unclear whether this will make it to the final specification. There is no implementation in any browser today.

A debugging tool as browser extension could get access to these kinds of listeners, but I'm not aware of any that actually do.

Some JS frameworks leave enough of a record of event binding to work out what they've been up to. Visual Event takes this approach to discover listeners registered through a few popular frameworks.

这篇关于检查任何DOM元素的附加事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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