Jquery对话框异步模式

Jquery Dialog asynchronous mode

本文关键字:模式 异步 对话框 Jquery      更新时间:2023-09-26

我正在使用jQuery UI对话框编程一个应用程序。在onSubmit函数中,我希望用户可以确认加载文件,但由于对话框异步模式,代码没有提供确认用户选择的选项。当用户想要选择任何选项时,该功能已经结束。

有解决这个问题的办法吗?

这是代码:

onSubmit:function(files)
    {   
        var bucle=true;
            var perm=null;
            if(res=="0"){
                perm=true;
            }else if(res=="1"){
                if(showDialog()){
                    perm=true;
                }else{
                    perm=false;
                }
            }
            else{
                perm=false;
        }
        res=null;
        return perm;

    },

和showDialog功能:

function showDialog(){
$(function() {
    $.ui.dialog.prototype._focusTabbable = function(){};
    $( "#dialog-confirm" ).dialog({
      resizable: false,
      height:200,
      width:600,
      modal: true,
      closeText:null,
      buttons: {
        Ok: function() {
            $(this).dialog('close');
            return true;
        },
        Cancel: function() {
            $(this).dialog('close');
            return false;
        }
      }
    });
  });

}

提前谢谢!

由于异步模式,您需要等到用户做出选择
您可以将下一步作为回调传递给showDialog方法。

onSubmit:function(files){
  //non-relevant code omitted...
  showDialog(nextStep)
  //non-relevant code omitted...
}
function nextStep(trueOrFalse){
   if(trueOrFalse){
      // upload your file or do anything you want
   }else{
      // do another thing
   }
}
function showDialog(callback){
      //non-relevant code omitted...
      buttons: {
        Ok: function() {
            $(this).dialog('close');
            callback(true);
        },
        Cancel: function() {
            $(this).dialog('close');
            callback(false);
        }
      }
     //non-relevant code omitted...
  }