Bootstrap 警报按钮设计已关闭,单击时不会关闭

Rya*_*Tee 2 html css bootstrap-modal bootstrap-5

我正在尝试 Bootstrap,但 Bootstrap 警报按钮不知何故根本不起作用。我所做的就是从 Bootstrap 复制代码: 在此输入图像描述

但是页面显示的是这个?按钮的设计是关闭的,并且它不起作用(不关闭)。我检查了所有内容:alert-dismissible是否存在,按钮有data-dismiss = 'alert',但不知何故它不起作用。我包含的脚本是 Bootstrap 捆绑版本。 在此输入图像描述

Dou*_*aan 7

您更改了示例的一小部分:您data-dismiss应该是data-bs-dismiss并且按钮上的类应该是btn-close而不是close

<div class="alert alert-warning alert-dismissible fade show" role="alert">
  <strong>Holy guacamole!</strong> You should check in on some of those fields below.
  <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
Run Code Online (Sandbox Code Playgroud)

关于解雇的文件

经过仔细检查,我注意到您的警报是Boostrap 4 警报。在您的示例中,您使用 Bootstrap 5 中的 CSS 和 JavaScript,其中可忽略的警报应类似于上面的示例。

  • 我意识到我使用的是 Bootstrap 4 文档而不是 v5!多谢! (2认同)