attachEvent或addEventListener - 存储在哪里? [英] attachEvent or addEventListener - stored where?
问题描述
在JQuery中,如果我这样做...
In JQuery, if I do this...
$('a').click(function(){
// Do something
});
...点击事件存储在 $('a') .data('events')
,我可以像这样抓取它:
...the click event is stored at $('a').data('events')
and I can fetch it like so:
jQuery.each($('a').data('events'), function(i, event){
jQuery.each(event, function(i, handler){
if(handler.type.toString() == 'click')
{
// do something
}
});
});
通过 attachEvent
附加的事件 addEventListener
显然不会出现在 $('a')。data('events')
中。有什么可以迭代的地方吗?我假设他们在某个地方排队,但是我找不到文件来指出我的方向正确。
An event that is attached via attachEvent
or addEventListener
will obviously not appear in $('a').data('events')
. Is there anything I can iterate in its place? I assume they're queued up somewhere, but I can't find documentation to point me in the right direction.
推荐答案
如果您可以在页面开头安装代码,您可以在自己的数据结构中记录所有后续的监听器这种钩子:为什么Google +1记录我的鼠标移动?。
If you can get code installed at the beginning of the page, you can record all subsequent listeners in your own data structure with this kind of hook: Why does Google +1 record my mouse movements?.
我知道没有办法访问现有的听众。
I know of no way to access the existing listeners.
这篇关于attachEvent或addEventListener - 存储在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!