Bootstrap中的表单控件状态主要有三种:焦点状态,禁用状态,验证状态。
一、焦点状态:该状态告诉用户可输入或选择东西
焦点状态通过伪类“:focus”以实现。
bootstrap.css相应源码:
.form-control:focus { border-color: #66afe9; outline: 0; //删除了outline的默认样式 -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6); //添加了阴影效果 box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6);}使用方法:给控件添加类名“form-control”。
eg:
<input class="form-control" type="text" placeholder="不是焦点状态下效果"><input class="form-control" type="text" placeholder="焦点状态下效果">
效果图如下所示:(焦点状态下为蓝色边框效果)
焦点状态下,file、radio、checkbox控件的效果与普通的input空间不完全一样,因为bootstrap对它们做了特殊处理。
bootstrap.css相应源码:
input[type="file"]:focus,input[type="radio"]:focus,input[type="checkbox"]:focus {outline: thin dotted;outline: 5px auto -webkit-focus-ring-color;outline-offset: -2px;}
<strong>二、禁用状态:</strong>该状态告诉用户不可以输入或选择东西
禁用状态是通过在表单控件上添加"disabled"属性以实现。
bootstrap.css相应源码:
.form-control[disabled],.form-control[readonly],fieldset[disabled] .form-control { cursor: not-allowed; background-color: #eee; opacity: 1;}
使用方法:在需要禁用的表单控件上加上"diabled"属性即可。
eg:
<input class="form-control" type="text" placeholder="不是焦点状态下效果"><input class="form-control" type="text" placeholder="表单已禁用,不能输入" disabled>
效果图如下所示:
说明:禁用状态下控件背景色为灰色,且手型变为不准输入的形状,若表单控件不使用类名"form-control",则禁用的控件只有一个不准输入的手型。
PS:在Bootstrap中,若fieldset设置了"disabled"属性,则整个域都处于被禁用状态。
eg:
1 <form role="form"> 2 <fieldset disabled> 3 <div class="form-group"> 4 <label for="disabledTextInput">禁用的输入框</label> 5 <input type="text" id="disabledTextInput" class="form-control" placeholder="禁止输入"> 6 </div> 7 <div class="form-group"> 8 <label for="disabledSelect">禁用的下拉框</label> 9 <select id="disabledSelect" class="form-control">10 <option>不可选择</option>11 </select>12 </div>13 <div class="checkbox">14 <label>15 <input type="checkbox">无法选择16 </label>17 </div>18 <button type="submit" class="btnbtn-primary">提交</button>19 </fieldset>20 </form>
效果如下图所示:
PS:对于一个禁用的域,若legend中有输入框,则此输入框是无法被禁用的。
eg:
1 <form role="form"> 2 <fieldset disabled> 3 <legend><input type="text" class="form-control" placeholder="我没被禁用" /></legend> 4 <div class="form-group"> 5 <label for="disabledTextInput">禁用的输入框</label> 6 <input type="text" id="disabledTextInput" class="form-control" placeholder="禁止输入"> 7 </div> 8 <div class="form-group"> 9 <label for="disabledSelect">禁用的下拉框</label>10 <select id="disabledSelect" class="form-control">11 <option>不可选择</option>12 </select>13 </div>14 <div class="checkbox">15 <label>16 <input type="checkbox">无法选择17 </label>18 </div>19 <button type="submit" class="btnbtn-primary">提交</button>20 </fieldset> 21 </form>
效果图如下所示:
<strong>三、验证状态:</strong>该状态告诉用户,他们的操作是否正确在Bootstrap中提供3种验证状态样式:
① .has-success : 成功状态(绿色)
② .has-error : 错误状态(红色)
③ .has-warning : 警告状态(黄色)
使用方法:在form-group容器上添加对应的状态类名即可。
eg:
1 <form role="form"> 2 <div class="form-group has-success"> 3 <label class="control-label" for="inputSuccess1">成功状态</label> 4 <input type="text" class="form-control" id="inputSuccess1" placeholder="成功状态" > 5 </div> 6 <div class="form-group has-warning"> 7 <label class="control-label" for="inputWarning1">警告状态</label> 8 <input type="text" class="form-control" id="inputWarning1" placeholder="警告状态"> 9 </div>10 <div class="form-group has-error">11 <label class="control-label" for="inputError1">错误状态</label>12 <input type="text" class="form-control" id="inputError1" placeholder="错误状态">13 </div>14 </form>
说明:从效果可看出,三种样式除了颜色不同外,效果都一样。
在Bootstrap的表单验证中,不同状态会提供不同的icon,如成功是个对号"√",错误是个叉号"×"等。
若想让表单在不同状态下显示对应的icon,则只需在对应状态下添加类名"has-feedback"。
PS:类名"has-feedback"要与"has-error"、"has-warning"、"has-success"配合使用。
eg:
1 <form role="form"> 2 <div class="form-group has-success has-feedback"> 3 <label class="control-label" for="inputSuccess">成功状态</label> 4 <input type="text" class="form-control" id="inputSuccess" placeholder="成功状态" > 5 <span class="glyphicon glyphicon-ok form-control-feedback"></span> 6 </div> 7 <div class="form-group has-warning has-feedback"> 8 <label class="control-label" for="inputWarning">警告状态</label> 9 <input type="text" class="form-control" id="inputWarning" placeholder="警告状态" >10 <span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>11 </div> 12 <div class="form-group has-error has-feedback">13 <label class="control-label" for="inputError">错误状态</label>14 <input type="text" class="form-control" id="inputError" placeholder="错误状态" >15 <span class="glyphicon glyphicon-remove form-control-feedback"></span>16 </div> 17 </form>
效果如下所示:
说明:从效果图中可看出,图标都居右。
注:Bootstrap中的图标都是使用@face-face来制作,且必须在表单中添加个span元素来实现。
eg:
<span class="glyphicon glyphicon-remove form-control-feedback"></span>

HTML、CSS和JavaScript在Web開發中的作用分別是:1.HTML定義網頁結構,2.CSS控製網頁樣式,3.JavaScript添加動態行為。它們共同構建了現代網站的框架、美觀和交互性。

HTML的未來充滿了無限可能。 1)新功能和標準將包括更多的語義化標籤和WebComponents的普及。 2)網頁設計趨勢將繼續向響應式和無障礙設計發展。 3)性能優化將通過響應式圖片加載和延遲加載技術提升用戶體驗。

HTML、CSS和JavaScript在網頁開發中的角色分別是:HTML負責內容結構,CSS負責樣式,JavaScript負責動態行為。 1.HTML通過標籤定義網頁結構和內容,確保語義化。 2.CSS通過選擇器和屬性控製網頁樣式,使其美觀易讀。 3.JavaScript通過腳本控製網頁行為,實現動態和交互功能。

HTMLISNOTAPROGRAMMENGUAGE; ITISAMARKUMARKUPLAGUAGE.1)htmlStructures andFormatSwebContentusingtags.2)itworkswithcsssforstylingandjavascript for Interactivity,增強WebevebDevelopment。

HTML是構建網頁結構的基石。 1.HTML定義內容結構和語義,使用、、等標籤。 2.提供語義化標記,如、、等,提升SEO效果。 3.通過標籤實現用戶交互,需注意表單驗證。 4.使用、等高級元素結合JavaScript實現動態效果。 5.常見錯誤包括標籤未閉合和屬性值未加引號,需使用驗證工具。 6.優化策略包括減少HTTP請求、壓縮HTML、使用語義化標籤等。

HTML是一種用於構建網頁的語言,通過標籤和屬性定義網頁結構和內容。 1)HTML通過標籤組織文檔結構,如、。 2)瀏覽器解析HTML構建DOM並渲染網頁。 3)HTML5的新特性如、、增強了多媒體功能。 4)常見錯誤包括標籤未閉合和屬性值未加引號。 5)優化建議包括使用語義化標籤和減少文件大小。

WebDevelovermentReliesonHtml,CSS和JavaScript:1)HTMLStructuresContent,2)CSSStyleSIT和3)JavaScriptAddSstractivity,形成thebasisofmodernWebemodernWebExexperiences。

HTML的作用是通過標籤和屬性定義網頁的結構和內容。 1.HTML通過到、等標籤組織內容,使其易於閱讀和理解。 2.使用語義化標籤如、等增強可訪問性和SEO。 3.優化HTML代碼可以提高網頁加載速度和用戶體驗。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

SublimeText3漢化版
中文版,非常好用

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具