【问题标题】:Autoclose jquery modal dialog after showing an alert box显示警告框后自动关闭 jquery 模式对话框
【发布时间】:2011-12-20 18:16:10
【问题描述】:

我正在调用一个 jquery 模式对话框,其中有一个保存按钮。保存按钮依次进行 ajax 调用,成功时会显示​​一个警告框“数据已保存!”并带有一个确定按钮。到目前为止一切正常。

现在“数据已保存”警告框关闭后,我也想自动关闭之前调用的模态对话框。有没有人做过类似的事情?

 $( "#addFriendButton").click(function() {

        $( "#addNewFriend" ).dialog({
            title: 'Add a new friend.',
            height:'auto',
            width:'auto',
            modal: true
        });


    }); 
    //end addFriendButton

    $( "#saveNewFriendButton").click(function() {

        $.ajax({
          type: "POST",
          contentType: "application/json; charset=utf-8",
          url: "/api/bb/apiV1/addFriend",
          data: formToJSON(),
                      dataType: "json",
          success: function(responseDTO){

                        displayOKAlertBox(responseDTO.responseMessage);

          }
        });  


    }); 

  function displayOKAlertBox(message){

        $("#alertMsg").html(message);

        $( "#alertbox" ).dialog({
            modal: true,
            buttons: {
                Ok: function() {
                    $( this ).dialog( "close" );
                }
            }
        });

    }

【问题讨论】:

    标签: jquery-ui jquery dialog


    【解决方案1】:

    尝试以下方法:

    $("#alertbox").dialog({
            modal: true,
            buttons: {
                Ok: function() {
                    $('.ui-dialog').dialog('close');
                }
            }
    });
    

    【讨论】:

      【解决方案2】:

      试试下面的

      $( "#saveNewFriendButton").click(function() {
      
          $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "/api/bb/apiV1/addFriend",
            data: formToJSON(),
                        dataType: "json",
            success: function(responseDTO){
      
                          displayOKAlertBox(responseDTO.responseMessage);
                          $( "#alertbox" ).dialog("close");
      
            }
          });  
      
      
      });
      

      我认为这样可以,但也许我错了!

      【讨论】:

      • 我要关闭的对话框是 --> $( "#addNewFriend" ).dialog 而不是 $( "#alertbox" ).dialog
      猜你喜欢
      • 2018-08-02
      • 1970-01-01
      • 2014-06-21
      • 1970-01-01
      • 2011-07-10
      • 1970-01-01
      • 1970-01-01
      • 2019-02-13
      • 1970-01-01
      相关资源
      最近更新 更多