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

hen*_*ght 33 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>
Run Code Online (Sandbox Code Playgroud)

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

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

Mil*_*war 74

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

$('#myModal').on('hidden.bs.modal', function () {
 location.reload();
})
Run Code Online (Sandbox Code Playgroud)

演示

  • 如果动态添加模态,则将其添加到文档中。`$(document).on('hidden.bs.modal', '#Control_id', function (event) { // 关闭时运行的代码 });` 来源:/sf/answers/1544101191/ /2495584 (2认同)

Man*_*arz 9

试试这个按钮:

onclick="javascript:window.location.reload()"
Run Code Online (Sandbox Code Playgroud)

完整按钮:

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

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

  • 这也是我可以将我的脚本分开 - 而不是在按钮上有另一个属性. (2认同)

N J*_*N J 7

$('#myModal').on('hidden', function () {
  document.location.reload();
})
Run Code Online (Sandbox Code Playgroud)

演示