问题描述
我正在寻找。
似乎在Prototype 1.6+中不再使用Event.observers(可能是为了避免内存泄漏),所以如何跟踪什么事件侦听器附加到一个元素?
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?
我知道Firebug有一个break on next按钮,但是在我可以获得行为之前,body元素上有几个鼠标监听器我想要另一个特定的元素,还有其他方法吗?
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?
推荐答案
我已经更新了答案,更全面的原型
覆盖版本 1.6.0
更改为 1.6.1
。
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
.
它之间很混乱,但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!') }"
})
这篇关于更新:如何在原型中的DOM节点上查找事件监听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!