推荐 最新
拽嘻嘻

如何在事件监听器中传递 'this' 参数?

addEventListener('keydown', myFunction), removeEventListener('keydown', myFunction) 怎么在myFunction传参数 this? function myFunction(_this){ console.log(_this) } 解决方法: removeEventListener 123 // 点击事件函数 const eventClickFunc = (e) => { handleDivClick(e, this) } const container = document.querySelector('.container') container.addEventListener('click', eventClickFunc) // 监听 click function handleDivClick(e, _this) { console.log(e.target, _this); } // 取消监听 click function onRemoveEventListener() { console.log(1); const container = document.querySelector('.container') container.removeEventListener('click', eventClickFunc) }

0
1
0
浏览量17