检索事件列表
有没有办法在 Javascript 中检索 DOM 的事件列表?
例如,我使用 AddEvent 或 AddEventListener 方法为 onclick 事件注册 FuncA、FuncB、FuncC。 如何获取该 onclick 事件的所有这些函数的引用?
理想情况下,我想要一个像这样的函数:
eventList = getEvents(obj, 'onclick');
并将获取数组中的事件。
任何想法?
或者我可以使用任何功能来“暂停”事件并稍后“恢复”? 例如 我想暂停 obj.click 一段时间,直到发生某些事情,然后恢复它。 我不想删除所有事件并将它们重新注册。
我知道有事件停止传播功能,但无法恢复。
Is there any way to retrieve a list of events of a DOM in Javascript?
e.g. I register FuncA, FuncB, FuncC for the onclick event using AddEvent or AddEventListener methods. How do I get the reference of all these functions for that onclick event?
Ideally, I want to have a function like this:
eventList = getEvents(obj, 'onclick');
and will get the events in an array.
Any idea?
or Any function that I can use to "PAUSE" an event and "RESUME" later? e.g.
I want to pause obj.click for a while until something happens, then resume it. I don't want to remove all the events and register them back.
I know there is event stop propagation function, but that one cannot be resumed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一些挂钩到 addEvent 或 addEvent 侦听器的东西,然后跟踪它的添加/删除。 但我不会重写这个,因为 jQuery 已经这样做了。
这是完全相同的问题,但包含所有答案:
如何在调试时或从 JavaScript 代码中查找 DOM 节点上的事件侦听器?
(包含执行您想要的操作的三种方法)
Create something which hooks into addEvent or addEvent listener and then track it the additions/subtractions. But I wouldn't rewrite this, as jQuery already does it.
Here's the exact same question, but with all the answers:
How to find event listeners on a DOM node when debugging or from the JavaScript code?
(contains three methods of doing what you want)