在javascript中可以使用对话框返回一个变量,例如:
//sets variable as false
var shouldIngest = false;
//depends if cancel, ok, or the "x" is clicked
shouldIngest = confirm("Do you want to ingest?");
if( shouldIngest ) {
//do some things...
}else{
//do something else...
}
我想使用 jQuery UI dialog所以我可以稍微自定义/设置确认框的样式。我如何使用 jQuery UI 对话框实现相同的目的?我想捕获 var shouldIngest
的对话结果。下面的代码似乎不起作用。
var shouldIngest = false;
$('#ingestConfirmDialog').html('Do you want to Ingest this document into the form?');
shouldIngest = $('#ingestConfirmDialog').dialog({
modal : true,
draggable : false,
buttons : {
"Yes Ingest this Docx" : function () {
$(this).dialog("close");
},
"Just Add as Attachment" : function () {
$(this).dialog("close");
}
}
});
我该怎么做才能解决这个问题?提前谢谢你。
最佳答案
只需在按钮回调中设置变量:
buttons : {
"Yes Ingest this Docx" : function () {
shouldIngest = true;
$(this).dialog("close");
},
"Just Add as Attachment" : function () {
shouldIngest = false;
$(this).dialog("close");
}
}
或者,由于您使用按钮来确定是否应该执行某些操作,因此只需跳过设置标志并执行操作即可:
buttons : {
"Yes Ingest this Docx" : function () {
callYouIngestionMethod();
$(this).dialog("close");
},
"Just Add as Attachment" : function () {
// just close the dialog
$(this).dialog("close");
}
}
关于javascript - 确定 jquery 对话框的结果。将对话的结果分配给变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34358369/