更新:如何在原型中的 DOM 节点上查找事件侦听器?

发布于 2024-12-03 07:08:45 字数 296 浏览 0 评论 0原文

我正在寻找此问题的更新答案

似乎在 Prototype 1.6+ 中不再使用 Event.observers(可能是为了避免内存泄漏),那么我现在如何跟踪哪些事件侦听器附加到元素呢?

我知道 Firebug 有一个“下一个中断”按钮,但是在我可以在另一个特定元素上实现我想要的行为之前,body 元素上有几个鼠标侦听器会执行,那么还有其他方法吗?

I'm looking for an updated answer to this question.

It seems that Event.observers is no longer used (perhaps to avoid memory leaks) in Prototype 1.6+, so how do I track down now what event listeners are attached to an element?

I know Firebug has a "break on next" button, but there are several mouse listeners on the body element that execute before I can get to the behavior that I want on another particular element, so is there some other way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

纸短情长 2024-12-10 07:08:45

我已将您链接到的答案更新为更全面的Prototype覆盖范围考虑了版本1.6.01.6.1的变化。

中间变得非常混乱,但 1.6.1 有点干净:

var handler = function() { alert('clicked!') };
$(element).observe('click', handler);

// inspect
var clickEvents = element.getStorage().get('prototype_event_registry').get('click');
clickEvents.each(function(wrapper){
    alert(wrapper.handler) // alerts "function() { alert('clicked!') }"
})

I've update the answer you linked to with more comprehensive Prototype coverage accounting for changes in versions 1.6.0 to 1.6.1.

It got very messy in between there, but 1.6.1 is somewhat clean:

var handler = function() { alert('clicked!') };
$(element).observe('click', handler);

// inspect
var clickEvents = element.getStorage().get('prototype_event_registry').get('click');
clickEvents.each(function(wrapper){
    alert(wrapper.handler) // alerts "function() { alert('clicked!') }"
})
旧梦荧光笔 2024-12-10 07:08:45

现在,事物通过 Element 存储进行路由:)

Element.getStorage(yourElement).get('prototype_event_registry') 将为您提供 Prototype 的 Hash 实例,因此您可以执行任何操作你会用哈希来做。

// to see which event types are being observed
Element.getStorage(yourElement).get('prototype_event_registry').keys();

// to get array of handlers for particular event type
Element.getStorage(yourElement).get('prototype_event_registry').get('click');

// to get array of all handlers
Element.getStorage(yourElement).get('prototype_event_registry').values();

// etc.

请注意,这些是未记录的内部详细信息,将来可能会更改,因此除了调试目的之外,我不会依赖它们。

Things are now routed through Element storage : )

Element.getStorage(yourElement).get('prototype_event_registry') will give you an instance of Prototype's Hash, so you can do anything that you would do with hash.

// to see which event types are being observed
Element.getStorage(yourElement).get('prototype_event_registry').keys();

// to get array of handlers for particular event type
Element.getStorage(yourElement).get('prototype_event_registry').get('click');

// to get array of all handlers
Element.getStorage(yourElement).get('prototype_event_registry').values();

// etc.

Note that these are undocumented internal details which might be changed in the future, so I wouldn't rely on them except for, perhaps, debugging purposes.

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