Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.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 - Fatal编程技术网

让JavaScript函数等待Jquery对话框的结果

让JavaScript函数等待Jquery对话框的结果,javascript,jquery,Javascript,Jquery,假设我有function1,它需要function2的结果才能继续 但是function2通过触发Jquery对话框窗口打开,并提示用户从两个按钮中选择一个来获得所需的功能 然后,选择这两个按钮使function2执行其工作,并将其传递给function1 如何将在对话框窗口中选择按钮时给出的值返回到function2 请参阅下面的代码 $('#choice-dialog').dialog({ autoOpen: false, resizable: false, height:

假设我有function1,它需要function2的结果才能继续

但是function2通过触发Jquery对话框窗口打开,并提示用户从两个按钮中选择一个来获得所需的功能

然后,选择这两个按钮使function2执行其工作,并将其传递给function1

如何将在对话框窗口中选择按钮时给出的值返回到function2

请参阅下面的代码

$('#choice-dialog').dialog({
   autoOpen: false,
   resizable: false,
   height:140,
   modal: true,
   buttons: {
      "Proceed": function() {
         $( this ).dialog( "close" );
         true //the value to be sent to function2;
      },
      Cancel: function() {
         $( this ).dialog( "close" );
         false //the value to be sent to function2;
      }
   }
});

function function1(){
   if(function2(variable)===true){
      return true
   }
}

var function2 = function(variable){
   if(idIsUsed){
      $("#choice-dialog").dialog("open");
      return **choice made by user via dialog**;
   }else{
      return true;
   }
}

你不能这样做。最好重新构造代码,以便对话框使用
true
false
调用另一个函数:

$('#choice-dialog').dialog({
   autoOpen: false,
   resizable: false,
   height:140,
   modal: true,
   buttons: {
      "Proceed": function() {
         $( this ).dialog( "close" );
         otherFunction(true);
      },
      Cancel: function() {
         $( this ).dialog( "close" );
         otherFunction(false);
      }
   }
});

var function2 = function(variable){
   if(idIsUsed){
      $j("#choice-dialog").dialog("open"); 
   } else {
      otherFunction(true);
   }
}