出于某种原因,jQuery.off('click')似乎没有在这里工作.当在模型中单击"是"按钮时,会弹出另一个模型.我究竟做错了什么?
码:
$(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
});
});
})();
}
});
Run Code Online (Sandbox Code Playgroud)
小智 10
很确定你需要为它提供相同的元素,以及相同的选择器.
$('#signRentalContainer').off('click', '.renewal-warning');
Run Code Online (Sandbox Code Playgroud)
在.on()处理程序中,this是'.renewal-warning'单击的元素,而不是#signRentalContainer元素.
如果有多个这些'.renewal-warning'元素,并且您只想一次禁用一个元素,最简单的方法是更改其类,使其不再与选择器匹配.
$(this).removeClass('renewal-warning')
.addClass('renewal-warning-disabled');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16843 次 |
| 最近记录: |