我有一个函数begin
,它声明了一个处理函数为check
的addEventListener。现在,在check
内部满足特定条件时,我想要移除eventListener。从处理函数中删除窗口事件监听器
我的代码:
function begin(data){
//code
window.addEventListener('keyUp', check(data));
}
function check(data){
return function check1(event){
//code
if(condition) window.removeEventListener('keyUp', check(data));
}
}
一切工作正常但不删除EventListener
。
的可能的复制[如何removeEventListener这是使用封闭加入?](https://stackoverflow.com/questions/19774202/how-to-removeeventlistener-that-was-added-using-closure) –
Psst,它是removeEventListener(),而不是removeListener():)另外:阅读回答。 –