搜尋
首頁web前端前端問答bootstrap可對表單設定哪三種狀態

bootstrap可對表單設定的三種狀態:1、焦點狀態,該狀態告訴使用者可輸入或選擇東西;2、停用狀態,該狀態告訴使用者不可以輸入或選擇東西;3、驗證狀態,該狀態告訴用戶,其進行的操作是否正確。

bootstrap可對表單設定哪三種狀態

本教學操作環境:Windows7系統、bootsrap3.3.7版、DELL G3電腦

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="焦点状态下效果">

效果圖如下所示:(焦點狀態下為藍色邊框效果)

bootstrap可對表單設定哪三種狀態

焦點狀態下,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;
}

#二、停用狀態:此狀態告訴使用者不可以輸入或選擇東西

#禁用狀態是透過在表單控制項上新增"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>

效果圖如下所示:

bootstrap可對表單設定哪三種狀態

#說明:停用狀態下控制項背景色為灰色,且手型變成不准輸入的形狀,若表單控制不使用類別名稱"form-control",則停用的控制項只有一個不准輸入的手型。

PS:在Bootstrap中,若fieldset設定了"disabled"屬性,則整個域都處於停用狀態。

eg:

<form role="form">
    <fieldset disabled>
        <div class="form-group">
            <label for="disabledTextInput">禁用的输入框</label>
            <input type="text" id="disabledTextInput" class="form-control" placeholder="禁止输入">
        </div>
        <div class="form-group">
            <label for="disabledSelect">禁用的下拉框</label>
            <select id="disabledSelect" class="form-control">
                <option>不可选择</option>
            </select>
        </div>
        <div class="checkbox">
            <label>
                <input type="checkbox">无法选择
            </label>
        </div>
        <button type="submit" class="btnbtn-primary">提交</button>
    </fieldset>
</form>

效果如下圖所示:

bootstrap可對表單設定哪三種狀態

#PS:對於一個停用的域,若在legend中有輸入框,則此輸入框是無法被停用的。

eg:

<form role="form">
    <fieldset disabled>
        <legend><input type="text" class="form-control" placeholder="我没被禁用" /></legend>
        <div class="form-group">
            <label for="disabledTextInput">禁用的输入框</label>
            <input type="text" id="disabledTextInput" class="form-control" placeholder="禁止输入">
        </div>
        <div class="form-group">
            <label for="disabledSelect">禁用的下拉框</label>
            <select id="disabledSelect" class="form-control">
                <option>不可选择</option>
            </select>
        </div>
        <div class="checkbox">
            <label>
                <input type="checkbox">无法选择
            </label>
        </div>
        <button type="submit" class="btnbtn-primary">提交</button>
  </fieldset>
</form>

效果圖如下圖:

bootstrap可對表單設定哪三種狀態


#三、驗證狀態:該狀態告訴用戶,他們的操作是否正確

在Bootstrap中提供3種驗證狀態樣式:

① .has-success :成功狀態(綠色)

② .has-error : 錯誤狀態(紅色)

③ .has-warning : 警告狀態(黃色)


#使用方法:在form -group容器上新增對應的狀態類別名稱即可。

eg:

<form role="form">
    <div class="form-group has-success">
        <label class="control-label" for="inputSuccess1">成功状态</label>
        <input type="text" class="form-control" id="inputSuccess1" placeholder="成功状态" >
    </div>
    <div class="form-group has-warning">
        <label class="control-label" for="inputWarning1">警告状态</label>
        <input type="text" class="form-control" id="inputWarning1" placeholder="警告状态">
    </div>
    <div class="form-group has-error">
        <label class="control-label" for="inputError1">错误状态</label>
        <input type="text" class="form-control" id="inputError1" placeholder="错误状态">
    </div>
</form>

說明:從效果可看出,三種樣式除了顏色不同外,效果都一樣。 bootstrap可對表單設定哪三種狀態

在Bootstrap的表單驗證中,不同狀態會提供不同的icon,如成功是個對號"√",錯誤是個叉號"×"等。

若想讓表單在不同狀態下顯示對應的icon,則只需在對應狀態下新增類別名稱"has-feedback"。

PS:類別名稱"has-feedback"要與"has-error"、"has-warning"、"has-success"配合使用。


eg:

<form role="form">
    <div class="form-group has-success has-feedback">
        <label class="control-label" for="inputSuccess">成功状态</label>
        <input type="text" class="form-control" id="inputSuccess" placeholder="成功状态" >
        <span class="glyphicon glyphicon-ok form-control-feedback"></span>
    </div>
    <div class="form-group has-warning has-feedback">
        <label class="control-label" for="inputWarning">警告状态</label>
        <input type="text" class="form-control" id="inputWarning" placeholder="警告状态" >
        <span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>
  </div>
  <div class="form-group has-error has-feedback">
        <label class="control-label" for="inputError">错误状态</label>
        <input type="text" class="form-control" id="inputError" placeholder="错误状态" >
        <span class="glyphicon glyphicon-remove form-control-feedback"></span>
  </div>
</form>
效果如下圖:

##########:從效果圖中可看出,圖示都居右。 ######附註:Bootstrap中的圖示都是使用@face-face來製作,必須在表單中加入個span元素來實現。 ######eg:######
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
###【相關推薦:《###bootstrap教學###》】###

以上是bootstrap可對表單設定哪三種狀態的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
React中的鑰匙:深入研究性能優化技術React中的鑰匙:深入研究性能優化技術May 01, 2025 am 12:25 AM

KeysinreactarecrucialforopTimizingPerformanceByingIneFefitedListupDates.1)useKeyStoIndentifyAndTrackListelements.2)避免使用ArrayIndi​​cesasKeystopreventperformansissues.3)ChooSestableIdentifierslikeIdentifierSlikeItem.idtomaintainAinainCommaintOnconMaintOmentStateAteanDimpperperFermerfermperfermerformperfermerformfermerformfermerformfermerment.ChosestopReventPerformissues.3)

反應中的鍵是什麼?反應中的鍵是什麼?May 01, 2025 am 12:25 AM

ReactKeySareUniqueIdentifiers usedwhenrenderingListstoimprovereConciliation效率。 1)heelPreactrackChangesInListItems,2)使用StableanDuniqueIdentifiersLikeItifiersLikeItemidSisRecumended,3)避免使用ArrayIndi​​cesaskeyindicesaskeystopreventopReventOpReventSissUseSuseSuseWithReRefers和4)

反應中獨特鍵的重要性:避免常見的陷阱反應中獨特鍵的重要性:避免常見的陷阱May 01, 2025 am 12:19 AM

獨特的keysarecrucialinreactforoptimizingRendering和MaintainingComponentStateTegrity.1)useanaturalAlaluniqueIdentifierFromyourDataiFabable.2)ifnonaturalalientedifierexistsistsists,generateauniqueKeyniqueKeyKeyLiquekeyperaliqeyAliqueLiqueAlighatiSaliqueLiberaryLlikikeuuId.3)deversearrayIndi​​ceSaskeyseSecialIndiceSeasseAsialIndiceAseAsialIndiceAsiall

將索引用作react中的鍵將索引用作react中的鍵May 01, 2025 am 12:17 AM

使用索引作為鍵在React中是可以接受的,但僅限於列表項順序不變且不會動態添加或刪除的情況;否則,應使用穩定且唯一的標識符作為鍵。 1)在靜態列表(如下拉菜單選項)中使用索引作為鍵是可以的。 2)如果列表項可以重新排序、添加或刪除,使用索引會導致狀態丟失和意外行為。 3)始終使用數據的唯一ID或生成的標識符(如UUID)作為鍵,以確保React正確更新DOM和維護組件狀態。

React的JSX語法:對UI設計的開發人員友好方法React的JSX語法:對UI設計的開發人員友好方法May 01, 2025 am 12:13 AM

jsxisspecialbecialbecapeitblendshtmlwithjavascript,enableComponent-lase-uidesign.1)itallowsembeddingjavascriptInhtml-likesyntax,EnhancinguidesignAndLogicIntegration.2)

使用HTML5可以播放哪種類型的音頻文件?使用HTML5可以播放哪種類型的音頻文件?Apr 30, 2025 pm 02:59 PM

本文討論了HTML5音頻格式和跨瀏覽器兼容性。它涵蓋MP3,WAV,OGG,AAC和WebM,並建議使用多個來源和後備以實現更廣泛的可訪問性。

SVG和Canvas HTML5元素之間的區別?SVG和Canvas HTML5元素之間的區別?Apr 30, 2025 pm 02:58 PM

SVG和畫布是Web圖形的HTML5元素。基於向量的SVG擅長可擴展性和交互性,而基於像素的畫布則更適合遊戲等性能密集型應用程序。

使用HTML5可能會拖放嗎?使用HTML5可能會拖放嗎?Apr 30, 2025 pm 02:57 PM

HTML5可以通過特定的事件和屬性進行拖放,從而允許自定義,但面臨舊版本和移動設備上的瀏覽器兼容性問題。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SecLists

SecLists

SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。