javascript jQuery UI 对话框关闭时刷新父页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32826173/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 15:47:46  来源:igfitidea点击:

Refresh parent page when jQuery UI Dialog is closed

javascriptjquery

提问by George Baca

So every time a specific dialog box in jQuery UI is closed I want the parent page to be refreshed. How can I achieve this.

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

jQuery Code:

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 Code:

HTML代码:

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

How do I get the main parent page to refresh/reload after the dialog box is closed?

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

回答by Bernhard

Use the dialogclose event (http://api.jqueryui.com/dialog/#event-close).

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

回答by CDelaney

You should be able to do this with the reload()function:

您应该可以使用以下reload()功能执行此操作:

window.location.reload();

In your code:

在您的代码中:

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

回答by epascarello

When you initialize the dialog, add the close listener.

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

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