gpt4 book ai didi

javascript - attachEvent 或 addEventListener - 存储在哪里?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:37:24 25 4
gpt4 key购买 nike

在 jQuery 中,如果我这样做...

$('a').click(function(){
// Do something
});

...点击事件存储在 $('a').data('events') 中,我可以像这样获取它:

jQuery.each($('a').data('events'), function(i, event){  
jQuery.each(event, function(i, handler){
if(handler.type.toString() == 'click')
{
// do something
}
});
});

通过 attachEventaddEventListener 附加的事件显然不会出现在 $('a').data('events')。有什么我可以迭代的地方吗?我假设他们在某个地方排队,但我找不到可以为我指明正确方向的文档。

最佳答案

来自 quirksmode :

One problem of the current implementation of W3C’s event registration model is that you can’t find out if any event handlers are already registered to an element. In the traditional model you could do:

alert(element.onclick)

and you see the function that’s registered to it, or undefined if nothing is registered. Only in its very recent DOM Level 3 Events W3C adds an eventListenerList to store a list of event handlers that are currently registered on an element. This functionality is not yet supported by any browser, it’s too new. However, the problem has been addressed.

关于javascript - attachEvent 或 addEventListener - 存储在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6886792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com