由于某种原因,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