由於某種原因,jQuery.off('click')在這裏似乎不起作用。當模型中點擊「是」按鈕時,會彈出另一個模型。我究竟做錯了什麼?jQuery.off()沒有刪除綁定
代碼:
$(function(){
//If there are warnings on the page bind alert
if ($('.renewal-warning').length > 0){
(function(){
$('#signRentalContainer').on('click', '.renewal-warning', function(e){
var buttonHandle = this;
//Prevent submission
e.preventDefault();
//Show warning model
$.modal({
content: $('#renewalWarning').html(),
title: "Order Renewal Warning",
buttons: {
'Yes': function(win) { $(buttonHandle).off('click').click(); },
'No': function(win) { win.closeModal(); }
},
maxWidth: 250,
closeButton: false
});
});
})();
}
});
爲什麼不是在這種情況下,處理工作?我認爲jQuery改變了範圍以匹配事件? – Steven 2012-01-15 08:00:10
@Steven:哦,那是你爲什麼要做'.off()'?我猜這個事件正在冒泡。嘗試添加'e.stopPropagation()'到處理程序,而不是'off()'。 – 2012-01-15 08:02:32
......或者這是因爲你正在對已被點擊的元素執行'.click()'。那是爲什麼?嘗試刪除它。 – 2012-01-15 08:03:40