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

Mic*_*ael 3 javascript jquery object

我有这个:

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

testInstance = new test();

testInstance = null;  // delete window.testInstace;
Run Code Online (Sandbox Code Playgroud)

虽然我已经通过设置testInstance为null 删除了对该对象的引用(我也尝试将其作为属性删除window),但mousemove事件处理程序继续操作并写入控制台.如果删除建立事件处理程序的对象没有删除它,那么我该怎么做才能删除事件处理程序?

Abb*_*bas 16

如果您使用的是jquery 1.7

$('html').off('mousemove');
Run Code Online (Sandbox Code Playgroud)

其他

$('html').unbind('mousemove');
Run Code Online (Sandbox Code Playgroud)