我尝试制作一个与bpopup(iframe)函数一起使用的jquery函数。我想显示确认消息,然后再尝试关闭iframe。我添加了一条确认消息,该消息会在更改后显示,但是在我提交表单后,确认框就会重复。我尝试调试并检查了函数执行了多少次,所以我做了console.log,但是当确认消息多次执行时,这个console.log只执行了一次。这是功能:
function confirm_changed(){
var changed = false;
$('.b-modal', parent.document).on('click', function(){
if(changed && confirm('Weet je zeker dat je dit scherm wilt verlaten?')){
$('.b-modal', parent.document).removeClass('changed');
}
});
$(document).one('input', function(){
$('.b-modal', parent.document).addClass('changed');
changed = true;
});
}
此函数在document.ready中被调用,这是bpopup原型函数,在其中我添加了确认消息的条件:
function r(){
setTimeout(function(){
if(c('.changed').length === 0){
a.modal && c(".b-modal." + b.data("id")).fadeTo(a.speed, 0, function(){
c(this).remove()
});
a.scrollBar || c("html").css("overflow", "auto");
c(".b-modal." + e).unbind("click");
f.unbind("keydown." + e);
k.unbind("." + e).data("bPopup", 0 < k.data("bPopup") - 1 ? k.data("bPopup") - 1 : null);
b.undelegate(".bClose, ." + a.closeClass, "click." + e, r).data("bPopup", null);
clearTimeout(H);
G();
return !1
}
}, 0);
}
此功能关闭iframe。
我添加了超时,以便在确认消息后执行此功能。提交表单后,所有内容都通过验证,该类将被删除。