[英]How can I delete a jQuery event handler?
I have this: 我有这个:
function test()
{
this.method = function ()
{
$("html").mousemove(function(event) {
console.log('~> moved');
});
}
this.method();
}
testInstance = new test();
testInstance = null; // delete window.testInstace;
Although I have removed references to the object by setting testInstance
to null (I've also tried deleting it as a property of window
), the mousemove event handler continues to operate and write to the console. 虽然我已经通过将testInstance
设置为null来删除对该对象的引用(我还尝试将其作为window
的属性删除),但mousemove事件处理程序继续操作并写入控制台。 If deleting the object that established the event handler doesn't remove it what then should I do to remove the event handler? 如果删除建立事件处理程序的对象没有删除它,那么我该怎么做才能删除事件处理程序?
if you are using jquery 1.7 如果您使用的是jquery 1.7
$('html').off('mousemove');
else 其他
$('html').unbind('mousemove');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.