【问题标题】:Jquery Dialog asynchronous modeJquery Dialog异步模式
【发布时间】:2016-03-30 14:20:22
【问题描述】:

我正在使用 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;
        }
      }
    });

  });

}

提前谢谢你!

【问题讨论】:

    标签: javascript jquery jquery-ui asynchronous dialog


    【解决方案1】:

    由于异步模式,您需要等到用户做出选择。
    您可以将下一步作为回调传递给 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...
      }
    

    【讨论】:

      猜你喜欢
      • 2011-10-21
      • 2011-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-18
      • 2011-03-25
      相关资源
      最近更新 更多