我知道这对大家来说都是一个非常简单的问题,但是我是一个初学者,我想弄清楚如何在条件语句中调用带有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>
答案 0 :(得分:0)
您可以在使用两个按钮的地方使用确认框。
<!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 >