有没有办法通过Javascript查找元素的事件处理程序? [英] Is there a way to find the event handlers of an element with Javascript?

查看:134
本文介绍了有没有办法通过Javascript查找元素的事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说你有这个div:

<div id="foo">bar</div>

你这样做:

$("#foo").click(someFunction);

您的JavaScript代码中的某个地方。

somewhere inside your javascript code.

页面加载完毕后,有没有办法通过firebug或chrome检查元素或其他任何东西找出#foo的点击事件绑定到 someFunction ?也就是说,没有必要查看所有的代码?

Once the page has been loaded, is there a way to find out, via firebug or inspect element in chrome, or anything else, that the click event for #foo is bound to someFunction? I.e, find this out without having to look through all your code?

推荐答案

Chrome开发人员工具这样做。

Chrome Developer tools does this.


  1. 右键点击元素

  2. 点击检查元素

  3. 在右侧列中,向下滚动到事件侦听器

这将为您提供对象上的事件侦听器列表,

This will give you a list of event listeners on the object that can be expanded to find their source and the attached function.

Firebug在DOM选项卡下有这样的信息,但不太用户友好。

Firebug has this information under the DOM tab, but it's less user friendly.

这篇关于有没有办法通过Javascript查找元素的事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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