这个问题在这里已经有了答案:
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 键按下时调用它。请问有什么帮助吗?提前致谢。
最佳答案
关于javascript - 如何检查javascript中是否存在事件监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47680365/