[英]Javascript confirm box, yes/no, it shows confirm box but never waits for the use to hit Yes. it automatically submits the form
JavaScript代碼:
if (s12.value < s10.value) {
$('<div></div>').appendTo('body')
.html('<div><h6>' + "Out Time is less than In Time. Is that ok??" + '</h6></div>')
.dialog({
modal: true,
title: 'Confirmation',
zIndex: 10000,
autoOpen: true,
width: 'auto',
resizable: true,
buttons: {
Yes: function () {
if (s10.value < s14.value || s14.value < s12.value) {
alertDialog("Time is not between out time and in time.");
} else {
$("#<%=Button1.ClientID%>").submit();
}
$(this).dialog("close");
},
No: function () {
$(this).dialog("close");
}
},
close: function (event, ui) {
$(this).remove();
}
});
< script >
function alertDialog(message) {
$('<div></div>').appendTo('body')
.html('<div><h6>' + message + '</h6></div>')
.dialog({
modal: true,
title: 'Errors',
zIndex: 10000,
autoOpen: true,
width: 'auto',
resizable: true,
buttons: {
Ok: function () {
$(this).dialog("close");
},
},
close: function (event, ui) {
$(this).remove();
}
});
}; < /script>
條件1: if (s12.value < s10.value)
則顯示確認框,提示“輸出時間小於輸入時間。可以嗎?”
如果用戶選擇是,則條件2: if (s10.value < s14.value || s14.value < s12.value)
則顯示警報框
否則,提交表格。
問題:能夠顯示確認框,但從不等待用戶點擊是/否,它會自動提交表單。
請幫忙。 提前致謝。
您應該創建不打開的對話框
var dialog_var = $('<div></div>').appendTo('body')
.html('<div><h6>' + message + '</h6></div>')
.dialog({
modal: true, title: 'Errors', zIndex: 10000, autoOpen: true,
width: 'auto', resizable: true,
buttons: {
Ok: function () {
$(this).dialog("close");
},
function alertDialog(message) {
$(dialog_var).dialog("open");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.