gpt4 book ai didi

javascript - 如何删除 jQuery 事件处理程序?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:50:38 25 4
gpt4 key购买 nike

我有这个:

function test()
{
this.method = function ()
{
$("html").mousemove(function(event) {
console.log('~> moved');
});
}
this.method();
}

testInstance = new test();

testInstance = null; // delete window.testInstace;

尽管我通过将 testInstance 设置为 null 删除了对该对象的引用(我也尝试将其作为 window 的属性删除),但 mousemove 事件处理程序继续操作并写入控制台。如果删除建立事件处理程序的对象不会删除它,那么我应该如何删除事件处理程序?

最佳答案

如果您使用的是 jquery 1.7

$('html').off('mousemove');

其他

$('html').unbind('mousemove');

关于javascript - 如何删除 jQuery 事件处理程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8684382/

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