我正在尝试解除事件绑定(bind)。
我的事件是:
$(window).on('drop', this.onFileSelect.bind(this));
后来我:
$(window).off('drop', this.onFileSelect.bind(this));
但我仍然可以放弃。
我哪里出错了?
最佳答案
在 jQuery 中识别事件监听器的推荐方法(通常用于以后删除)是使用 event namespacing ,在你的情况下:
$(window).on('drop.onfileselect', this.onFileSelect.bind(this));
然后:
$(window).off('drop.onfileselect');
请注意,onfileselect
是我选择的任意标识符,您可以提供自己的(插件)名称。
关于javascript - 使用开/关事件绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28412916/