删除元素及其子元素的所有JavaScript事件侦听器? [英] Remove all JavaScript event listeners of an element and its children?

查看:1331
本文介绍了删除元素及其子元素的所有JavaScript事件侦听器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以移除元素及其子元素的所有事件侦听器?类似的东西:

Is it possible to remove all event listeners of an element and its children? Something like:

myElem.removeEventListeners();

我需要这个,因为我有一个复杂的事件元素,我需要创建一个副本

I need this because I have a complex element with events, and I need to create a copy of it -- like a static image that does not react to any events.

推荐答案

如果使用 cloneNode ,则不会复制事件侦听器

If you use cloneNode, the event listeners won't be copied.

如果您需要一个强大的解决方案,写一个包装到 attach / detach 监听器,并自己跟踪它们。像 Dean Edwards的addEvent

If you want a robust solution your best bet is probably to write a wrapper to attach/detach listeners, and keep track of them yourself. Something like Dean Edwards' addEvent.

这篇关于删除元素及其子元素的所有JavaScript事件侦听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆