javascript - Bootstrap 4隐藏未关闭的警报

标签 javascript twitter-bootstrap alert bootstrap-4

正如标题所述,我想知道隐藏警报的最佳方法,以便我们可以在不重新加载页面的情况下获得另一个警报。这里有 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/

相关文章:

javascript - 使用 Javascript 清除元素的文本样式

javascript - 如何知道对象的标签类型?

jquery - 无法获取要调整大小的 Bootstrap 表

html - 在 Bootstrap 的面板中添加下划线

html - Javafx 警报对话框 + HTML

linux - 关于管理文件系统空间

javascript - 如何在 JS 代理中拦截排序功能?

javascript - 无法通过 Canvas 上的 WebApi 调用绘制图像

javascript - 根据开始日期和结束日期过滤 JSON

php - PHP 中的 JS 警报作为 AJAX 应用程序的一部分