函数对话框 2 按钮在状况下不起作用



我知道这对你们所有人来说都是一个非常简单的问题,但我是一个初学者,我正在试图弄清楚,如何调用带有 2 个按钮的对话框以及条件语句中的参数。我的代码没有调用该函数。它只显示一条警报消息。如果有人能启发错误,我将不胜感激,谢谢。

<div id="requirement #2">
<button type="button" id="button4" onclick="StringSearch1()">Search</button>
</div>
<script>
function StringSearch1() {
if (condition) {
stayonPage1(val1,val2,val3);
//  alert("textfield1 " + val1 + " Exists in textfield2 and its corresponding value in text 3 is " + val3);
//the alert message is working but I want to call the function dialogbox  to pop
} else {
//  alert("textfield1 " + val1 + " not Exists in textfield2 and its corresponding value in text 3 is " + val3)
}
}
function stayonPage1(val1,val2,val3){
var dialog = $("textfield1 " + val1 + " Exists in textfield2 and its corresponding value in text 3 is " + val3).dialog({
buttons: {
"Apply": function() {alert('you chose yes');},
"Cancel":  function() {
dialog.dialog('close');
}
}
});
}
</script>

您可以使用使用两个按钮的确认框。

<!DOCTYPE HTML>
<html>
<head>

<style>

</style>
</head >
<body>
<div id="requirement #2">
<button type="button" id="button4" onclick="StringSearch1()">Search</button>
</div>

<script>
function StringSearch1() {
var condition = true;
var val1 = '1', val2 = '2', val3 = '3';
if (condition) {
stayonPage1(val1, val2, val3);
} else {
}
}
function stayonPage1(val1, val2, val3) {
var Val = confirm("textfield1 " + val1 + " Exists in textfield2 and its corresponding value in text 3 is " + val3);
if (Val == true) {
alert('you chose yes');
return true;
}
else {
alert("close");
return false;
} 
//var dialog = $("textfield1 " + val1 + " Exists in textfield2 and its corresponding value in text 3 is " + val3).dialog({
//    buttons: {
//        "Apply": function () { alert('you chose yes'); },
//        "Cancel": function () {
//            dialog.dialog('close');
//        }
//    }
//});
}
</script>
</body>
</html >

最新更新