【发布时间】:2015-01-21 17:34:59
【问题描述】:
我想检查页面中的任何文本区域是否已更改,如果是,如果用户在未提交的情况下导航离开,则停止导航并提示模式窗口(而不是来自 onbeforeunload 的模式窗口)以检查用户是否想要真正离开页面或留下并提交数据。
到目前为止,我已经做到了:
var needToConfirm = false;
$("input,textarea").on("input", function () {
needToConfirm = true;
});
$("select").change(function () {
needToConfirm = true;
});
function closeEditorWarning() {
if (needToConfirm) {
var t = News;
t.config.modalTitle.html("If you exit this page, your unsaved changes will be lost"), t.config.modalMsg.text("Are you sure you don't want to submit the changes?"), t.config.modalWindow.show(), t.config.modalAcceptBtn.on(click, null)
return "null";
}
}
window.onbeforeunload = closeEditorWarning();
这样,我得到了模态弹出窗口,但随后页面被卸载到用户立即选择的页面,而忽略了模态窗口。那么如何防止页面被卸载并让它等待用户确认他想离开而不提交更改?
【问题讨论】:
标签: jquery modal-dialog