【问题标题】:do something when modal hides当模态隐藏时做某事
【发布时间】:2017-02-20 02:37:33
【问题描述】:

我遇到了一个模态的问题,我有一个,当我关闭它时我需要运行一些东西,实际上当它关闭时,我需要刷新 index.php。

<!DOCTYPE html>
<html>
<head>
    <script src="js/jquery.min_2.1.4.js"></script>
    <script src="js/bootstrap3.3.min.js"></script>
    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" />

    <script>

    $('#myModal').modal({
      'show': false
    });


    $('#btnModal').click(function() {

      $('#myModal').modal('show');
    });

    $('#myModal').on('hide', function(e) {
      if (!confirm('You want to close me?'))
        e.preventDefault();
    });
    </script>   

    </head>
<body><!-- Button trigger modal -->

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

<a role="button" class="btn" id="btnModal">Launch demo modal</a>

<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Modal header</h3>

  </div>
  <div class="modal-body">
    <p>One fine body…</p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-primary">Save changes</button>
  </div>
</div>

</body>
</html>

我有这个例子,但我做不到。有人可以帮助我吗?谢谢

【问题讨论】:

    标签: php jquery twitter-bootstrap modal-dialog


    【解决方案1】:

    Bootstrap 有自己的显示和隐藏事件名称:

    on('shown.bs.modal',function() { ... })

    on('hidden.bs.modal',function() { ... })

    希望对您有所帮助。 祝你好运!

    更新:更多引导程序的模式事件名称:

    show.bs.modal : 模态即将显示时发生
    shown.bs.modal : 模态完全显示时发生(CSS 转换完成后)
    hide.bs.modal : 模态即将显示时发生被隐藏
    hidden.bs.modal : 当模态完全隐藏时发生(在 CSS 转换完成后)

    请参阅 Bootstrap 文档以获取更多参考:http://getbootstrap.com/javascript/#modals-events

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-13
      • 2018-05-13
      • 2012-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多