- Bootstrap 教程
- Bootstrap - 首頁
- Bootstrap - 概述
- Bootstrap - 環境設定
- Bootstrap - RTL
- Bootstrap - CSS 變數
- Bootstrap - 色彩模式
- Bootstrap 佈局
- Bootstrap - 斷點
- Bootstrap - 容器
- Bootstrap - 網格系統
- Bootstrap - 列
- Bootstrap - 間距
- Bootstrap - 實用程式
- Bootstrap - CSS 網格
- Bootstrap 元件
- Bootstrap - 手風琴
- Bootstrap - 警告框
- Bootstrap - 徽章
- Bootstrap - 麵包屑
- Bootstrap - 按鈕
- Bootstrap - 按鈕組
- Bootstrap - 卡片
- Bootstrap - 走馬燈
- Bootstrap - 關閉按鈕
- Bootstrap - 摺疊
- Bootstrap - 下拉選單
- Bootstrap - 列表組
- Bootstrap - 模態框
- Bootstrap - 導航欄
- Bootstrap - 導航和標籤
- Bootstrap - 側邊欄
- Bootstrap - 分頁
- Bootstrap - 佔位符
- Bootstrap - 氣泡提示
- Bootstrap - 進度條
- Bootstrap - 滾動偵聽
- Bootstrap - 載入動畫
- Bootstrap - 提示框
- Bootstrap - 工具提示
- Bootstrap 表單
- Bootstrap - 表單
- Bootstrap - 表單控制元件
- Bootstrap - 選擇框
- Bootstrap - 複選框和單選按鈕
- Bootstrap - 範圍滑塊
- Bootstrap - 輸入組
- Bootstrap - 浮動標籤
- Bootstrap - 佈局
- Bootstrap - 驗證
- Bootstrap 輔助工具
- Bootstrap - 清除浮動
- Bootstrap - 顏色和背景
- Bootstrap - 彩色連結
- Bootstrap - 聚焦環
- Bootstrap - 圖示連結
- Bootstrap - 定位
- Bootstrap - 寬高比
- Bootstrap - 堆疊
- Bootstrap - 拉伸連結
- Bootstrap - 文字截斷
- Bootstrap - 垂直線
- Bootstrap - 視覺隱藏
- Bootstrap 實用工具
- Bootstrap - 背景
- Bootstrap - 邊框
- Bootstrap - 顏色
- Bootstrap - 顯示
- Bootstrap - Flexbox
- Bootstrap - 浮動
- Bootstrap - 互動
- Bootstrap - 連結
- Bootstrap - 物件適應
- Bootstrap - 不透明度
- Bootstrap - 溢位
- Bootstrap - 定位
- Bootstrap - 陰影
- Bootstrap - 尺寸
- Bootstrap - 間距
- Bootstrap - 文字
- Bootstrap - 垂直對齊
- Bootstrap - 可見性
- Bootstrap 演示
- Bootstrap - 網格演示
- Bootstrap - 按鈕演示
- Bootstrap - 導航演示
- Bootstrap - 部落格演示
- Bootstrap - 滑塊演示
- Bootstrap - 走馬燈演示
- Bootstrap - 標題演示
- Bootstrap - 頁尾演示
- Bootstrap - 英雄區演示
- Bootstrap - 特色演示
- Bootstrap - 側邊欄演示
- Bootstrap - 下拉選單演示
- Bootstrap - 列表組演示
- Bootstrap - 模態框演示
- Bootstrap - 徽章演示
- Bootstrap - 麵包屑演示
- Bootstrap - 特大標題演示
- Bootstrap - 粘性頁尾演示
- Bootstrap - 相簿演示
- Bootstrap - 登入演示
- Bootstrap - 定價演示
- Bootstrap - 結賬演示
- Bootstrap - 產品演示
- Bootstrap - 封面演示
- Bootstrap - 儀表盤演示
- Bootstrap - 粘性頁尾導航欄演示
- Bootstrap - 砌體佈局演示
- Bootstrap - 啟動模板演示
- Bootstrap - 相簿 RTL 演示
- Bootstrap - 結賬 RTL 演示
- Bootstrap - 走馬燈 RTL 演示
- Bootstrap - 部落格 RTL 演示
- Bootstrap - 儀表盤 RTL 演示
- Bootstrap 有用資源
- Bootstrap - 問題與解答
- Bootstrap - 快速指南
- Bootstrap - 有用資源
- Bootstrap - 討論
Bootstrap - 警告外掛
警告訊息主要用於向終端使用者顯示資訊,例如警告或確認訊息。使用警告訊息外掛,您可以為所有警告訊息新增關閉功能。
如果您想單獨包含此外掛功能,則需要 alert.js。否則,如 Bootstrap 外掛概述 一章所述,您可以包含 bootstrap.js 或壓縮後的 bootstrap.min.js。
用法
您可以透過以下兩種方式啟用警告框的關閉功能:
透過資料屬性 - 要透過資料 API 關閉,只需將 data-dismiss = "alert" 新增到您的關閉按鈕,即可自動賦予警告框關閉功能。
<a class = "close" data-dismiss = "alert" href = "#" aria-hidden = "true"> × </a>
透過 JavaScript - 要透過 JavaScript 關閉,請使用以下語法:
$(".alert").alert()
示例
以下示例演示瞭如何透過資料屬性使用警告外掛。
<div class = "alert alert-success">
<a href = "#" class = "close" data-dismiss = "alert">
×
</a>
<strong>Warning!</strong> There was a problem with your network connection.
</div>
選項
這裡沒有選項。
方法
以下是警告外掛的一些有用方法:
| 方法 | 描述 | 示例 |
|---|---|---|
| .alert() | 此方法將所有警告框包裝上關閉功能。 |
$('#identifier').alert();
|
關閉方法 .alert('close') |
要啟用所有警告框的關閉功能,請新增此方法。 |
$('#identifier').alert('close');
|
要啟用警告框在關閉時淡出動畫,請確保它們已應用 .fade 和 .in 類。
示例
以下示例演示瞭如何使用 .alert() 方法:
<h3>Alert messages to demonstrate alert() method </h3>
<div id = "myAlert" class = "alert alert-success">
<a href = "#" class = "close" data-dismiss = "alert">×</a>
<strong>Success!</strong> the result is successful.
</div>
<div id = "myAlert" class = "alert alert-warning">
<a href = "#" class = "close" data-dismiss = "alert">×</a>
<strong>Warning!</strong> There was a problem with your network connection.
</div>
<script type = "text/javascript">
$(function(){
$(".close").click(function(){
$("#myAlert").alert();
});
});
</script>
以下示例演示瞭如何使用 .alert('close') 方法:
<h3>Alert messages to demonstrate alert('close') method </h3>
<div id = "myAlert" class = "alert alert-success">
<a href = "#" class = "close" data-dismiss = "alert">×</a>
<strong>Success!</strong> the result is successful.
</div>
<div id = "myAlert" class = "alert alert-warning">
<a href = "#" class = "close" data-dismiss = "alert">×</a>
<strong>Warning!</strong> There was a problem with your network connection.
</div>
<script type = "text/javascript">
$(function(){
$(".close").click(function(){
$("#myAlert").alert('close');
});
});
</script>
使用 嘗試一下 編輯器嘗試此程式碼。您可以看到關閉功能已應用於所有警告訊息,即關閉任何警告訊息,其餘警告訊息也會關閉。
事件
下表列出了與警告外掛一起使用的事件。此事件可用於掛接到警告功能。
| 事件 | 描述 | 示例 |
|---|---|---|
| close.bs.alert | 當呼叫 close 例項方法時,此事件會立即觸發。 |
$('#myalert').bind('close.bs.alert', function () {
// do something
})
|
| closed.bs.alert | 當警告框已關閉時觸發此事件(將等待 CSS 過渡完成)。 |
$('#myalert').bind('closed.bs.alert', function () {
// do something
})
|
示例
以下示例演示了警告外掛事件:
<div id = "myAlert" class = "alert alert-success">
<a href = "#" class = "close" data-dismiss = "alert">×</a>
<strong>Success!</strong> the result is successful.
</div>
<script type = "text/javascript">
$(function(){
$("#myAlert").bind('closed.bs.alert', function () {
alert("Alert message box is closed.");
});
});
</script>
廣告