var mouseListener = button2.addEventListener("mouseover", function (e) {
count++;
...
if(count > 5) button2.removeEventListener("mouseover", mouseListener);
});
我不知道为什么代码不起作用?如何在javascript中使用removeEventListener ()
?
答案 0 :(得分:0)
listener
是您在function
函数中传递的addEventListener
。
var mouseListener = function (e) {
count++;
...
if ( count > 5 ) {
button2.removeEventListener("mouseover", mouseListener);
}
}
button2.addEventListener("mouseover", mouseListener);
文档:
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener