javascript - 使用开/关事件绑定(bind)?

标签 javascript jquery

我正在尝试解除事件绑定(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/

相关文章:

jquery - Gmaps4rails : map not showing when loaded dynamically

javascript - find() 函数在 jquery 中的页面加载时不起作用

c# - 如何在.Net中不使用滚动条来移动 GridView 的行

javascript - 在单击事件处理程序中调用自定义 jQuery 插件会生成错误

javascript - 通过 Javascript Bookmarklet 保存浏览器历史记录

javascript - Appcelerator TableView > 行 > 文本字段 > 值

jquery - CSS 转换 - RotateY 不符合要求

javascript - javaScript中模块关闭之前和模块关闭之后 '()'或 '(otherModule)'之间的区别

javascript - jQuery Datatables 和 ColumnFilterWidget 集成问题

javascript - 计算具有特定属性的 child 的数量