[英]How can I delete a jQuery event handler?
我有这个:
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');
销毁对象不会对您添加的事件处理程序产生任何影响。 要删除事件处理程序,您需要取消绑定事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.