gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 21:52:25 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com