W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
Bootstrap 允許您為網(wǎng)站或 app 的成功執(zhí)行、警告和錯(cuò)誤信息定義樣式。在本教程中,您將學(xué)習(xí)如何做到這點(diǎn)。
使用 CSS class "alert",位于 bootstrap.css 中的行號(hào) 2123 到 2175(版本 2.0.1),您可以創(chuàng)建一個(gè)簡(jiǎn)單警告信息。您可以為它添加一個(gè)可選的關(guān)閉圖標(biāo)。
當(dāng)您點(diǎn)擊警告框中的關(guān)閉圖標(biāo)時(shí),警告框關(guān)閉。要想實(shí)現(xiàn)這個(gè)交互效果,您必須添加兩個(gè) JavaScript 文件 jquery.js 和 alert.js。您可以把它們添加到 body 元素關(guān)閉標(biāo)簽前面。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Basic alerts with twitter bootstrap</title> <meta name="description" content="Creating basic alerts with Twitter Bootstrap. Examples of alerts and errors with Twitter Bootstrap"> <link href="/twitter-bootstrap/twitter-bootstrap-v2/docs/assets/css/bootstrap.css" rel="stylesheet"> <style type="text/css"> body { padding: 50px; } </style> </head> <body> <div class="container"> <div class="row"> <div class="span4"> <div class="alert"> <a class="close" data-dismiss="alert">×</a> <strong>Warning!</strong> Best check yo self, you're not looking too good. </div> </div> </div> </div> <script src="twitter-bootstrap-v2/docs/assets/js/jquery.js"></script> <script src="twitter-bootstrap-v2/docs/assets/js/bootstrap-alert.js"></script> </body> </html>
請(qǐng)注意,行號(hào) 18 到 21 之間的代碼是必需的。這些僅是為了實(shí)例演示。
通過(guò)另外兩個(gè) CSS classes "alert-block " 和 "alert-heading",您可以擴(kuò)展前面演示的簡(jiǎn)單的警告信息。它讓您更好地控制要顯示的文本,而且您可以在警告文本前添加文本標(biāo)題。
當(dāng)您點(diǎn)擊警告框中的關(guān)閉圖標(biāo)時(shí),警告框關(guān)閉。要想實(shí)現(xiàn)這個(gè)交互效果,您必須添加兩個(gè) JavaScript 文件 jquery.js 和 alert.js。您可以把它們添加到 body 元素關(guān)閉標(biāo)簽前面。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Extending simple alert with twitter bootstrap</title> <meta name="description" content="Extending simple alert with twitter bootstrap."> <link href="/twitter-bootstrap/twitter-bootstrap-v2/docs/assets/css/bootstrap.css" rel="stylesheet"> <style type="text/css"> body { padding: 50px; } </style> </head> <body> <div class="container"> <div class="row"> <div class="span4"> <div class="alert alert-block"> <a class="close" data-dismiss="alert">×</a> <h4 class="alert-heading">Warning!</h4> What are you doing?! this will delete all files!! </div> </div> </div> </div> <script src="twitter-bootstrap-v2/docs/assets/js/jquery.js"></script> <script src="twitter-bootstrap-v2/docs/assets/js/bootstrap-alert.js"></script> </body> </html>
Bootstrap 允許您在錯(cuò)誤或危險(xiǎn)、成功和信息發(fā)生時(shí)創(chuàng)建何時(shí)的警告。對(duì)于錯(cuò)誤(error),您需要 CSS class "alert-error"。對(duì)于成功(success),您需要 "alert-success" class。對(duì)于信息(information),您需要 class "alert-info"。當(dāng)然,就像前面的實(shí)例中說(shuō)明的一樣,您需要 JS 文件 jquery.js 和 alert.js。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Example alerts on error success and information with Twitter bootstrap</title> <meta name="description" content="Example alerts on error success and information with Twitter bootstrap."> <link href="/twitter-bootstrap/twitter-bootstrap-v2/docs/assets/css/bootstrap.css" rel="stylesheet"> <style type="text/css"> body { padding: 50px; } </style> </head> <body> <div class="alert alert-error"> <a class="close" data-dismiss="alert">×</a> <strong>Error!</strong>This is a fatal error. </div> <div class="alert alert-success"> <a class="close" data-dismiss="alert">×</a> <strong>Success!</strong>You have successfully done it. </div> <div class="alert alert-info"> <a class="close" data-dismiss="alert">×</a> <strong>Info!</strong>Watch this, but you may forget. </div> <script src="twitter-bootstrap-v2/docs/assets/js/jquery.js"></script> <script src="twitter-bootstrap-v2/docs/assets/js/bootstrap-alert.js"></script> </body> </html>
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: