您可以使用对话框来在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");
}
}
});
我该怎么做才能解决这个问题?提前谢谢。
答案 0 :(得分:1)
只需在按钮回调中设置变量:
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");
}
}