【问题标题】:Refresh parent page when jQuery UI Dialog is closedjQuery UI 对话框关闭时刷新父页面
【发布时间】:2015-09-28 15:03:05
【问题描述】:

因此,每次关闭 jQuery UI 中的特定对话框时,我都希望刷新父页面。我怎样才能做到这一点。

jQuery 代码:

        $(document).ready(function() { 
         var dlg=$('#createTeam').dialog({
         title: 'Create a Team',
         resizable: true,
         autoOpen:false,
         modal: true,
         hide: 'fade',
         width:600,
         height:285
      });


      $('#createTeamLink').click(function(e) {
          dlg.load('admin/addTeam.php');
          e.preventDefault();
          dlg.dialog('open');
      }); 
}); 

HTML 代码:

<button href="" type="button" id="createTeamLink" class="btn btn-primary custom">Create Team</button>
<div id="createTeam" class="divider"></div>

对话框关闭后如何让主父页面刷新/重新加载?

【问题讨论】:

  • 对话是承诺吗?您可以使用它并在调用刷新函数之前等待结果......@Bernhard 所说的。

标签: javascript jquery


【解决方案1】:

使用 dialogclose 事件 (http://api.jqueryui.com/dialog/#event-close)。

var dlg=$('#createTeam').dialog({
     title: 'Create a Team',
     resizable: true,
     autoOpen:false,
     modal: true,
     hide: 'fade',
     width:600,
     height:285,
     close: function(event, ui) {
          location.reload();
     }
  });

【讨论】:

  • 效果很好,谢谢。我会在 5 分钟内接受答案。
  • 您知道如何通过单击对话框外部来关闭对话框吗?
  • 查看这个问题和答案:stackoverflow.com/questions/2554779/…
【解决方案2】:

您应该可以使用reload() 函数来做到这一点:

window.location.reload();

在您的代码中:

var dlg=$('#createTeam').dialog({
     title: 'Create a Team',
     resizable: true,
     autoOpen:false,
     modal: true,
     hide: 'fade',
     width:600,
     height:285,
     close: function() {
         window.location.reload();
     }
});

【讨论】:

    【解决方案3】:

    初始化对话框时,添加close listener

    $( ".selector" ).dialog({
      close: function( event, ui ) { window.location.reload(true); }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-14
      • 1970-01-01
      • 1970-01-01
      • 2012-01-15
      • 1970-01-01
      • 2022-11-21
      相关资源
      最近更新 更多