【问题标题】:Capture BootstrapNative Modal close event without jQuery在没有 jQuery 的情况下捕获 BootstrapNative 模态关闭事件
【发布时间】:2020-02-14 12:05:52
【问题描述】:

我正在使用Bootstrap-Native,我想检测模式何时关闭,有没有办法用普通的javascript来做到这一点?

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

我试过了:

document.getElementById("exampleModal").addEventListener("transitionend", console.log("closed"));

但是事件没有触发。

【问题讨论】:

标签: javascript bootstrap-modal bootstrap-native


【解决方案1】:

这个问题可以在这里重复找到:Bind a function to Twitter Bootstrap Modal Close

查看答案:

var myModalEl = document.getElementById('myModalID');
myModalEl.addEventListener('hidden.bs.modal', function (event) {
    // do something...
});

【讨论】:

    猜你喜欢
    • 2014-04-29
    • 1970-01-01
    • 2012-10-12
    • 1970-01-01
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-26
    相关资源
    最近更新 更多