我试图在bootstrap关闭时触发回调函数。但它没有用。我用过的代码:
<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)你是否以正确的方式包括了图书馆: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>