我有下面这段代码:删除的事件处理程序的jQuery
jQuery.noConflict();
var x=0;
myw=0;
oin="";
jQuery(document).ready(function() {
if(x >3){
$("img:odd").unbind("mouseenter");
return false;
}
jQuery("img:odd").mouseenter(function(e) {
// oin="";
console.log(e);
console.log(this);
console.log(this.src);
oin=this.src;
this.src="snowdrop.png";
myw=this.width;
this.width=100;
x=x+1;
console.log(x);
jQuery(this).css("opacity", 0.5);
}).mouseout(function(e) {
this.width=myw;
this.src=oin;
jQuery(this).css("opacity", 1.0);
});
});
的代码运行正常,但我想要做的是后3点鼠标悬停(的mouseenter)我想禁用MouseEnter事件。我无法弄清楚如何解除它?
感谢, 吉姆
我发现这个工作最好。但我也加了$(elem).off('mouseleave');因为即使在mouseenter被删除之后,图像仍在被交换。 –
是的,有时删除这两个处理程序是必要的! – adeneo
这让我开始正确,但我也必须改变所有的引用,例如elem.width = 100 TO this.width = 100 - 原因是没有什么事情发生在上面的代码试图使宽度的图像EVENT 100像素宽。但理论上它是最好的。 –