Javascript 如何删除jQuery事件处理程序?
我有这个:Javascript 如何删除jQuery事件处理程序?,javascript,jquery,object,Javascript,Jquery,Object,我有这个: function test() { this.method = function () { $("html").mousemove(function(event) { console.log('~> moved'); }); } this.method(); } test
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');
否则
销毁对象不会对您添加的事件处理程序产生任何影响。要删除事件处理程序,您需要删除该事件。您必须显式解除事件处理程序的绑定。Checkout JS没有“删除”对象的概念。可能重复
$('html').unbind('mousemove');