关闭jQuery UI Dialog时刷新父页面

Refresh parent page when jQuery UI Dialog is closed

本文关键字:刷新 jQuery UI Dialog 关闭      更新时间:2023-09-26

所以每次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>

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

使用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();
     }
  });

您应该能够使用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();
     }
});

初始化对话框时,添加close侦听器

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