隐藏的弹出事件不适用于引导程序模式

时间:2018-11-05 13:50:20

标签: twitter-bootstrap bootstrap-4

我正在尝试在启动关闭时触发回调函数。但这是行不通的。我使用的代码:

<div class="modal" id="overlayyy" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="custom-modal modal-dialog modal-dialog-centered" role="document">
    <div class="container">
      <div class="modal-content">
        <div class="modal-body text-center">
          <iframe class="custom-iframe" id="myModalll" src="<?php echo $link; ?>"></iframe>
        </div>
      </div>
    </div>
  </div>
</div>

使用的JS:

$('#overlayyy').on('hidden.bs.modal', function ()
{
    alert('hide event fired!');
});

1 个答案:

答案 0 :(得分:1)

请务必检查以下几点:

1)您是否以正确的方式包含了该库:Bootstrap Starter Guide

2),以防万一,删除模式中的container类。

3)检查您的custom-modal类是否与Bootstrap Modal冲突。

您可以使用代码作为基础来检查下一个工作示例。

$('#overlayyy').on('hidden.bs.modal', function()
{
    alert('hide event fired!');
});
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

<!-- Button to trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#overlayyy">
  Open Modal
</button>

<!-- Modal -->
<div class="modal" id="overlayyy" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
    <div class="modal-content">

      <div class="modal-body text-center">
        <iframe class="custom-iframe" id="myModalll" src=""></iframe>
      </div>

    </div>
  </div>
</div>