正如标题所述,我想知道隐藏警报的最佳方法,以便我们可以在不重新加载页面的情况下获得另一个警报。这里有 BS3 的几个答案,但我希望 BS4 有更好的解决方案。
这是我的 HTML:
<div style="display: none;" class="alert alert-danger alert-with-icon" data-notify="container">
<div class="container">
<div class="alert-wrapper">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<i class="nc-icon nc-simple-remove"></i>
</button>
<div class="message"><i class="nc-icon nc-bell-55"></i>
My alert message.
</div>
</div>
</div>
</div>
我用它来触发打开警报:
$('.alert').show();
最佳答案
您只需添加一个监听器即可覆盖默认行为。这对我有用:
$(".alert").on("close.bs.alert", function () {
$alertMsg.hide();
return false;
});
该解决方案由 Winifred Cadap 在他的博客上提供。可以找到here .
关于javascript - Bootstrap 4隐藏未关闭的警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47067026/