作者sk1765 (爱是一种忍耐)
看板Ajax
标题[问题] off('mouseenter') 的问题
时间Mon Jun 25 15:19:24 2012
我尝试用 .off("mouseenter", handler);
但是不发生作用 程式如下
http://jsfiddle.net/7bPnP/11/
<button id="theone">Does nothing...</button>
<button id="bind">Add Click</button>
<div id='msg' style="display:none;">Click!</div>
<div id="thetwo" style="width:200px;height:200px;background-color:red"></div>
$(document).ready( function() {
function aClick() {
$("#msg").show().fadeOut("slow");
$("#theone").off("click", aClick)
.text("Does nothing...");
}
$("#bind").click(function () {
$("#theone").on("click", aClick)
.text("Can Click!");
});
});
$(document).ready( function() {
function aenter() {
alert('mouse enter');
$("#thetwo").off("mouseente", aenter);
}
$("#thetwo").on("mouseenter", aenter);
});
主要是 $("#thetwo").off("mouseente", aenter);
是放在 handler function中
如果不是放在handler function中 就会正常被取消
而第一段程式 $("#theone").off("click", aClick)
off click放在 handler function中也正常
所以同样是将off放在handler function中
click正常 mouseenter却失败
这是bug吗 不知道有没有人试过
--
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 175.181.46.55
1F:→ elliot79313:打错字而已...mouseente要改成mouseenter 06/26 02:16
2F:→ sk1765:sorry我这边范例打错字了 可我的程式还是挂 我比较一下 06/26 08:08