将函数放入变量中,这样以后使用时就可以引用它
removeEventListener
。Eg公司
document.addEventListener('keydown', theListener);
function theListener(e) {
if (e.which === 13) {
document.getElementById(imageID).click();
console.log('keydown activated');
console.log('removing keydown... ');
document.removeEventListener('keydown', theListener);
console.log('keydown removed');
}
}
第二个参数
删除EventListener
必须与中使用的函数完全相同
addEventListener
-它不会识别您刚刚声明为在侦听器列表中的新函数。