删除匿名事件侦听器 [英] Removing an anonymous event listener

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

问题描述

无论如何要删除像这样添加的事件监听器:

Is there anyway to remove an event listener added like this:

element.addEventListener(event, function(){/* do work here */}, false);

而不更换元素?

推荐答案

除非您在创建时存储了对事件处理程序的引用,否则无法干净地删除事件处理程序。

There is no way to cleanly remove an event handler unless you stored a reference to the event handler at creation.

我通常会添加这些对应于该页面上的主要对象,然后您可以在完成该对象时迭代并干净地处理它们。

I will generally add these to the main object on that page, then you can iterate and cleanly dispose of them when done with that object.

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

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