查看事件侦听器 - Javascript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17795211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
View event listeners - Javascript
提问by iConnor
I'm wondering if it is possible to view
我想知道是否可以查看
1. How many event listeners
1. 多少个事件监听器
2. What type of event listener
2. 什么类型的事件监听器
On a single web page.
在单个网页上。
Reason being is becuase im using off();
method.
原因是因为我正在使用off();
方法。
I'm using this framework, which is basically jQuery but not.
我正在使用这个框架,它基本上是 jQuery 但不是。
Yeah, I'm using off but the even't isn't removing and and I have a feeling there is more than one eventListener
on the element.
是的,我正在使用 off 但即使没有删除,而且我觉得eventListener
元素上有不止一个。
If it is not possible with javascript, it is possible in the browser?
如果使用 javascript 无法实现,那么在浏览器中可以实现吗?
回答by iConnor
A long time passes...
很长一段时间过去了...
I have found something new in Chrome DevTools.
我在 Chrome DevTools 中发现了一些新东西。
Simple as this in the console
就这么简单 console
getEventListeners(yourElement);
Documentation: https://developers.google.com/chrome-developer-tools
回答by Parris
Chrome has some built in tools. If you open up the element inspector, focus on an element, scroll to the bottom of the right hand column (where the CSS/Metrics/etc are), you should see a drop down section that says Event Listeners. This can help some...
Chrome 有一些内置工具。如果您打开元素检查器,将焦点放在一个元素上,滚动到右侧列的底部(CSS/Metrics/etc 所在的位置),您应该会看到一个下拉部分,上面写着 Event Listeners。这可以帮助一些...
Often I find it easier to just add event listeners to some DOM element via the console and seeing if it responds. Or I throw in debuggers in various places (before setting up the listener, and inside the listener's callback). The problems I usually run into is the selector I think exists doesn't or the event gets bound too early and misses the selector.
通常我发现通过控制台向某个 DOM 元素添加事件侦听器并查看它是否响应更容易。或者我在不同的地方加入调试器(在设置监听器之前,以及在监听器的回调中)。我通常遇到的问题是我认为不存在的选择器或事件过早绑定而错过了选择器。
回答by Robbie
You can use the Visual Event bookmarklet: http://www.sprymedia.co.uk/article/Visual+Event+2
您可以使用 Visual Event 书签:http: //www.sprymedia.co.uk/article/Visual+Event+2