问题描述
- JS 如何取消绑定的监听事件
-
var x = document.getElementById('b1');
x.addEventListener('click',aaa,false);
取消事件用 x.removeEventListener('click',aaa,false); 这个没有问题
但是如果用匿名函数绑定,那么怎么取消
x.addEventListener('click',function(){alert('niming')},false);运行 x.removeEventListener('click',function(){alert('niming')},false); 无效
解决方案
匿名的无法取消,一定要有函数名才行。。
时间: 2024-09-17 04:27:17