作者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