检索事件列表

发布于 2024-07-18 03:38:01 字数 477 浏览 6 评论 0原文

有没有办法在 Javascript 中检索 DOM 的事件列表?

例如,我使用 AddEventAddEventListener 方法为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧竹 2024-07-25 03:38:01

创建一些挂钩到 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文