原生js如何从元素中移除事件监听器?
程序员文章站
2022-07-13 23:01:20
...
原生js如何从元素中移除事件监听器?
const off = (el, evt, fn, opts = false) => el.removeEventListener(evt, fn, opts);
const fn = () => console.log('!');
document.body.addEventListener('click', fn);
off(document.body, 'click', fn);