如何在关闭Bootstrap 3模式时重新加载页面

时间:2014-02-05 13:11:30

标签: javascript jquery twitter-bootstrap twitter-bootstrap-3

我的目标是在Bootstrap模式关闭时重新加载页面。用户可以通过单击关闭按钮或图标或单击远离模态来关闭模态。

到目前为止,我的代码非常标准。取自: http://getbootstrap.com/javascript/#modals

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch
</button>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">My title</h4>
      </div>
      <div class="modal-body">
        My content
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save</button>
      </div>
    </div>
  </div>
</div>

如何在模态关闭后重新加载页面?

更新:哇,来自每个人的惊人快速反应。谢谢

3 个答案:

答案 0 :(得分:72)

您可以点击关闭时将事件绑定到重新加载页面:

$('#myModal').on('hidden.bs.modal', function () {
 location.reload();
})

<强> Demo

答案 1 :(得分:8)

使用按钮尝试:

onclick="javascript:window.location.reload()"

完整按钮:

<button type="button" onclick="javascript:window.location.reload()" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

示例: http://jsfiddle.net/Valtos/52VtD/2288/embedded/result/

答案 2 :(得分:7)

$('#myModal').on('hidden', function () {
  document.location.reload();
})

Demo