导航从一页到另一页, 当我从一个页面导航到另一个页面时我希望jquery确认消息带有是和否按钮,如果我点击是然后去导航页面,如果点击否则它仍然在当前页面上。
对于这个使用jquery警报但是alertbox会在几秒后自动隐藏。 以下是代码
var needToConfirm = false;
var PageLeaveCount = $("#totalCount").val();
if (PageLeaveCount > 0) {
needToConfirm = true;
}
window.onbeforeunload = confirmExit;
function confirmExit() {
if (needToConfirm)
swal({
title: " Are you sure want to navigate?",
text: "If you navigate out of scrutiny page without completing scrutiny asset on this stage will not move to next stage.",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
cancelButtonText: "No",
closeOnConfirm: false,
closeOnCancel: false
},
function (isConfirm) {
if (isConfirm) {
return true;
}
else {
return false;
}
});
}
答案 0 :(得分:0)
尝试使用submit
事件处理程序和confirm
-
$("form").submit(function(){
return confirm('Are you sure you want to save this thing into the database?');
})