gpt4 book ai didi

javascript - 如何检查javascript中是否存在事件监听器

转载 作者:行者123 更新时间:2023-12-04 14:28:24 38 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Check if an element has event listener on it. No jQuery [duplicate]

(3 个回答)



How to check whether dynamically attached event listener exists or not?

(19 个回答)


3年前关闭。




我试图找到一种方法来检查 eventListener已经存在于一个窗口中,我已经尝试过这个 similar question 中的解决方案以及更多其他解决方案,但对我来说没有任何作用。

这是代码:

   checkEvent=function()
{
if('keydown' in window)
console.log('exist');
else
console.log('not_exist');
}

这是我在页面上添加的 eventListener 加载
document.addEventListener("keydown", PayKeydownHandler);

但是第一个代码,返回 'not_exist'其结果

PS:函数 checkEvent() ,我在 ENTER 键按下时调用它。

请问有什么帮助吗?提前致谢。

最佳答案

尝试这个

jQuery._data( window, "events" );

它在 jquery 1.8 中工作。阅读 this jQuery blog post .

关于javascript - 如何检查javascript中是否存在事件监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47680365/

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