如何在 Bootstrap 中建立警告通知警報?
Bootstrap 提供了一組類和元件來建立警報訊息,這些訊息可用於通知使用者不同型別的資訊,例如錯誤、警告和成功訊息。警告警報通常用於通知使用者網站或應用程式上的問題或錯誤。
Bootstrap 中的“alert-warning”類用於發出警報並向用戶指示警告訊息。您可以使用它來向用戶傳達不同型別的訊息,例如成功、危險、資訊等,方法是使用不同的類,例如 alert-success、alertdanger、alert-info 等。
方法
我們在 Bootstrap 中建立警告通知警報有兩種不同的方法,包括以下方法:
使用“帶連結的警報”
使用“可關閉的警報”
讓我們詳細瞭解每個步驟。
方法 1:使用“帶連結的方法”
第一種方法是在 Bootstrap 中建立警告通知警報作為“帶連結的警報”。帶連結的警報是一種包含連結的警告訊息,用於提供其他資訊或將使用者帶到特定頁面。此類警報通常用於通知使用者網站或應用程式上的潛在問題或錯誤。要在 Bootstrap 中建立帶連結的警報,您可以在警報元素內的錨標記(<a>)上使用“alert-link”類。
示例
以下是在 Bootstrap 中使用“帶連結的方法”建立警告通知警報的示例。
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Alert with Link</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" />
</head>
<body>
<div class="container py-5">
<h4 class="text-center text-uppercase">
Bootstrap Alert with Link
</h4>
<div class="alert alert-warning">
<strong>Warning!</strong>
There was a problem with the connection. <a href="#" class="alert-link">Please contact support.</a>
</div>
</div>
</body>
</html>
方法 2:使用“可關閉的方法”
第二種方法是在 Bootstrap 中建立警告通知警報作為“可關閉的警報”。它允許使用者透過單擊關閉按鈕輕鬆關閉警報。透過向警報新增“alert-dismissible”類,該類顯示一個關閉按鈕,使用者可以單擊該按鈕以關閉警報。
示例
以下是在 Bootstrap 中使用“可關閉的警報方法”建立警告通知警報的示例。
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container ">
<h4 class="text-center text-uppercase">
Example of a warning alert with a button
</h4>
<div class="alert alert-warning alert-dismissible fade show" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h5 class="alert-heading">Warning</h5>
<p>"This is a warning message. Please be aware that the content of this page may be outdated and should be used for informational purposes only. Any decisions or actions taken based on this information are the sole responsibility of the user. We recommend seeking professional advice before making any important decisions. Thank you for your understanding."</p>
<hr>
<p>Click the button to dismiss this alert.</p>
<button type="button" class="btn btn-secondary mt-3" datadismiss="alert">Dismiss</button>
</div>
</div>
</body>
</html>
結論
在本文中,我們研究了在 Bootstrap 中建立警告通知警報的兩種不同方法。在這裡,我們使用兩種不同的方法“帶連結的警報”和“可關閉的警報”。“帶連結的方法”涉及建立包含連結的警告訊息,以提供其他資訊或將使用者帶到特定頁面。“可關閉的警報”方法涉及建立使用者可以關閉的警告訊息。這兩種方法各有優缺點,具體取決於專案的具體需求。
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP