Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 确定jquery对话框的结果。将对话框的结果指定给变量_Javascript_Jquery_Jquery Ui - Fatal编程技术网

Javascript 确定jquery对话框的结果。将对话框的结果指定给变量

Javascript 确定jquery对话框的结果。将对话框的结果指定给变量,javascript,jquery,jquery-ui,Javascript,Jquery,Jquery Ui,您可以使用对话框返回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 e

您可以使用对话框返回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...
}
我想使用,这样我可以自定义/样式确认框一点。如何使用jQueryUI对话框实现同样的效果?我想捕获
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");
    }
 }

只需将要运行的代码“yes”和“no”放在这些按钮回调函数中即可。