removeEventListener无法正常工作 [英] removeEventListener is not working

查看:112
本文介绍了removeEventListener无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道我做错了什么,但这里有一个我正在做的事情的例子,它似乎不起作用。

I don't know what I am doing wrong but here is an example of what I am doing and it doesn't seem to work.

someDom.addEventListener('mousemove',function(ev) {self.onInputMove(ev)},false);

someDom.removeEventListener('mousemove',self.onInputMove);

执行removeEventListener代码,但它不会删除'mousemove'监听器

The removeEventListener code is executed but it just doesn't remove the 'mousemove' listener

推荐答案

removeEventListener 删除完全匹配函数的侦听器已添加。

removeEventListener removes the listener that exactly matches the function that was added.

在这种情况下,添加 addEventListener 的函数是:

In this case, the function that addEventListener added was:

var some_func = function(ev) {
    self.onInputMove(ev);
};

存储对实际功能的引用,你会很好。因此,例如,以下内容应该有效:

Store a reference to the actual function and you'll be good. So for example, the following should work:

someDom.addEventListener('mousemove',self.onInputMove,false);

someDom.removeEventListener('mousemove',self.onInputMove,false);

这篇关于removeEventListener无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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