非常教程

Bootstrap 4参考手册

组件·信息提示框 | Alerts

信息提示框 | Alerts

使用少量可用且灵活的警报消息为典型的用户操作提供环境反馈消息。

示例

警报可用于任何长度的文本,以及可选的解除按钮。为了正确的样式,使用八个必需的上下文类之一(例如,.alert-success)。对于内联解雇,使用警报 jQuery 插件。

在 getbootstrap.com 上打开示例

<div class="alert alert-primary" role="alert">
  This is a primary alert—check it out!
</div>
<div class="alert alert-secondary" role="alert">
  This is a secondary alert—check it out!
</div>
<div class="alert alert-success" role="alert">
  This is a success alert—check it out!
</div>
<div class="alert alert-danger" role="alert">
  This is a danger alert—check it out!
</div>
<div class="alert alert-warning" role="alert">
  This is a warning alert—check it out!
</div>
<div class="alert alert-info" role="alert">
  This is a info alert—check it out!
</div>
<div class="alert alert-light" role="alert">
  This is a light alert—check it out!
</div>
<div class="alert alert-dark" role="alert">
  This is a dark alert—check it out!
</div>

将意义传递给辅助技术

使用颜色来增加意义只能提供一种视觉指示,而不会传达给辅助技术的用户 - 如屏幕阅读器。确保由颜色表示的信息或者来自内容本身(例如可见文本),或者通过其他方式包含,例如隐藏在.sr-only类中的其他文本。

链接颜色

使用.alert-link工具类可以快速提供任何警报中匹配的彩色链接。

在 getbootstrap.com 上打开示例

<div class="alert alert-primary" role="alert">
  This is a primary alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-secondary" role="alert">
  This is a secondary alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-success" role="alert">
  This is a success alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-danger" role="alert">
  This is a danger alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-warning" role="alert">
  This is a warning alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-info" role="alert">
  This is a info alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-light" role="alert">
  This is a light alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>
<div class="alert alert-dark" role="alert">
  This is a dark alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
</div>

其他内容

警报还可以包含其他 HTML 元素,如标题,段落和分隔符。

在 getbootstrap.com 上打开示例

<div class="alert alert-success" role="alert">
  <h4 class="alert-heading">Well done!</h4>
  <p>Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.</p>
  <hr>
  <p class="mb-0">Whenever you need to, be sure to use margin utilities to keep things nice and tidy.</p>
</div>

驳回

使用警报 JavaScript 插件,可以解除任何内联警报。就是这样:

  • 确保你已经加载了警报插件,或编译好的 Bootstrap JavaScript。
  • 如果您从源代码构建我们的 JavaScript,则需要util.js。编译版本包括这个。
  • 添加一个解雇按钮和.alert-dismissible类别,在警报的右侧添加额外的填充并定位.close按钮。
  • 在 dismiss 按钮上,添加触发 JavaScript 功能的data-dismiss="alert"属性。请务必使用该<button>元素,以便在所有设备上正常运行。
  • 要解除它们的动画时,请务必添加.fade.show类。

你可以在现场演示中看到这一点:

在 getbootstrap.com 上打开示例

<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="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">&times;</span>
  </button>
</div>

JavaScript 行为

触发器

通过 JavaScript 启用解除警报:

$(".alert").alert()

或者通过警报中的按钮上的data属性,如上所示:

<button type="button" class="close" data-dismiss="alert" aria-label="Close">
  <span aria-hidden="true">&times;</span>
</button>

请注意,关闭警报会将其从 DOM 中删除。

方法

方法

描述

$().alert()

使警报侦听具有 data-dismiss =“alert”属性的后代元素上的点击事件。(使用 data-api 的自动初始化时不需要)。

$().alert('close')

通过从 DOM 中删除警报来关闭警报。如果元素上存在.fade 和.show 类,则警告将在删除之前淡出。

$().alert('dispose')

销毁元素的警报。

$(".alert").alert('close')

活动

引导程序的警报插件公开了一些事件,以便挂接到警报功能。

事件

描述

close.bs.alert

该事件在调用 close 实例方法时立即触发。

closed.bs.alert

警报关闭时将触发此事件(将等待 CSS 转换完成)​​。

$('#myAlert').on('closed.bs.alert', function () {
  // do something…
})

组件·信息提示框 | Alerts相关

Bootstrap 4

Bootstrap 是一套用于 HTML、CSS 和 JS 开发的开源工具集。利用我们提供的 Sass 变量和大量 mixin、响应式栅格系统、可扩展的预制组件、基于 jQuery 的强大的插件系统,能够快速为你的想法开发出原型或者构建整个 app 。

主页 https://getbootstrap.com/
源码 https://github.com/twbs/bootstrap
版本 4
发布版本 4.0.0-beta.2

Bootstrap 4目录

1.快速开始 | Getting started
2.组件·信息提示框 | Alerts
3.组件·徽章 | Badges
4.组件·面包屑导航 | Breadcrumb
5.组件·按钮组 | Button group
6.组件·按钮 | Buttons
7.组件·卡片 | Cards
8.组件·轮播 | Carousel
9.组件·折叠 | Collapse
10.组件·下拉菜单 | Dropdowns
11.组件·表单 | Forms
12.组件·输入框组 | Input group
13.组件·大屏幕 | Jumbotron
14.组件·列表组 | List group
15.组件·模态框 | Modal
16.组件·导航栏 | Navbar
17.组件·导航 | Navs
18.组件·分页 | Pagination
19.组件·弹出框 | Popovers
20.组件·进度条 | Progress
21.组件·滚动监听 | Scrollspy
22.组件·提示工具 | Tooltips
23.内容 | Content
24.布局 | Layout
25.迁移 | Migration
26.实用工具 | Utilities
27.Bootstrap4 网格系统
28.Bootstrap4 按钮组
29.Bootstrap4 按钮
30.Bootstrap4 图像形状
31.Bootstrap4 表格
32.Bootstrap4 颜色
33.Bootstrap4 文字排版
34.Bootstrap4 轮播
35.Bootstrap4 表单控件
36.Bootstrap4 表单
37.Bootstrap4 导航栏
38.Bootstrap4 导航
39.Bootstrap4 折叠
40.Bootstrap4 下拉菜单
41.Bootstrap4 卡片
42.Bootstrap4 分页
43.Bootstrap4 小工具
44.Bootstrap4 滚动监听
45.Bootstrap4 弹出框
46.Bootstrap4 提示框
47.Bootstrap4 模态框
48.Bootstrap 4 多媒体对象
49.Bootstrap 4 Flex(弹性)布局
50.Bootstrap4 创建一个网页
51.Bootstrap4 自定义表单
52.Bootstrap4 面包屑导航(Breadcrumb)