简体   繁体   English

如何从事件侦听器中 Chrome 控制台中提到的某些类别中删除所有事件侦听器

[英]How to remove all event listeners from certain categories that are mentioned in Chrome Console in Event Listeners

How do I remove all event listeners that are connected to the element that I can see in the Chrome Console in Event Listeners?如何删除连接到我可以在 Chrome 控制台中的事件侦听器中看到的元素的所有事件侦听器?

jQuery can be used if it will make it easier.如果 jQuery 更容易,可以使用它。

For example:例如:

This is tab in Chrome console.这是 Chrome 控制台中的选项卡。 Chrome 控制台

As you can see element is <a> but it as also some listeners from <div> , there is remove button next to each listener.正如您所看到的元素是<a>但它也是来自<div>一些侦听器,每个侦听器旁边都有删除按钮。

I would like to replicate something like this Remove button that deletes all listeners from mouseleave and mouseenter category.我想复制这样的删除按钮,从 mouseleave 和 mouseenter 类别中删除所有侦听器。

I have tried to use jQuery's .unbind('mouseleave mouseover') but it doesn't remove them.我曾尝试使用 jQuery 的.unbind('mouseleave mouseover')但它没有删除它们。

Is there any way how can I access all listeners from one category and remove them?有什么方法可以访问一个类别中的所有听众并删除它们?

You can replace it with a clone:您可以用克隆替换它:

const el = document.querySelector(...)
el.parentNode.replaceChild(el.cloneNode(true), el)

Then you can reattach the listened you still need if any.然后,您可以重新附加您仍然需要的已收听(如果有)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM