溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

bootstrap可對(duì)表單設(shè)置的狀態(tài)有哪些

發(fā)布時(shí)間:2022-01-10 14:14:07 來(lái)源:億速云 閱讀:141 作者:iii 欄目:web開發(fā)

這篇文章主要講解了“bootstrap可對(duì)表單設(shè)置的狀態(tài)有哪些”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“bootstrap可對(duì)表單設(shè)置的狀態(tài)有哪些”吧!

bootstrap可對(duì)表單設(shè)置的三種狀態(tài):1、焦點(diǎn)狀態(tài),該狀態(tài)告訴用戶可輸入或選擇東西;2、禁用狀態(tài),該狀態(tài)告訴用戶不可以輸入或選擇東西;3、驗(yàn)證狀態(tài),該狀態(tài)告訴用戶,其進(jìn)行的操作是否正確。

bootstrap可對(duì)表單設(shè)置的狀態(tài)有哪些

本教程操作環(huán)境:Windows7系統(tǒng)、bootsrap3.3.7版、DELL G3電腦

Bootstrap中的表單控件狀態(tài)主要有三種:焦點(diǎn)狀態(tài),禁用狀態(tài),驗(yàn)證狀態(tài)。

一、焦點(diǎn)狀態(tài):該狀態(tài)告訴用戶可輸入或選擇東西

焦點(diǎn)狀態(tài)通過(guò)偽類“:focus”以實(shí)現(xiàn)。

bootstrap.css相應(yīng)源碼:

.form-control:focus {
    border-color: #66afe9;
    outline: 0;   //刪除了outline的默認(rèn)樣式
    -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="不是焦點(diǎn)狀態(tài)下效果">
<input class="form-control" type="text" placeholder="焦點(diǎn)狀態(tài)下效果">

效果圖如下所示:(焦點(diǎn)狀態(tài)下為藍(lán)色邊框效果)

bootstrap可對(duì)表單設(shè)置的狀態(tài)有哪些

焦點(diǎn)狀態(tài)下,file、radio、checkbox控件的效果與普通的input空間不完全一樣,因?yàn)閎ootstrap對(duì)它們做了特殊處理。

bootstrap.css相應(yīng)源碼:

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;
}

二、禁用狀態(tài):該狀態(tài)告訴用戶不可以輸入或選擇東西

禁用狀態(tài)是通過(guò)在表單控件上添加"disabled"屬性以實(shí)現(xiàn)。
bootstrap.css相應(yīng)源碼:

.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="不是焦點(diǎn)狀態(tài)下效果">
<input class="form-control" type="text" placeholder="表單已禁用,不能輸入"  disabled>

效果圖如下所示:

bootstrap可對(duì)表單設(shè)置的狀態(tài)有哪些

說(shuō)明:禁用狀態(tài)下控件背景色為灰色,且手型變?yōu)椴粶?zhǔn)輸入的形狀,若表單控件不使用類名"form-control",則禁用的控件只有一個(gè)不準(zhǔn)輸入的手型。

PS:在Bootstrap中,若fieldset設(shè)置了"disabled"屬性,則整個(gè)域都處于被禁用狀態(tài)。

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">無(wú)法選擇
            </label>
        </div>
        <button type="submit" class="btnbtn-primary">提交</button>
    </fieldset>
</form>

效果如下圖所示:

bootstrap可對(duì)表單設(shè)置的狀態(tài)有哪些

PS:對(duì)于一個(gè)禁用的域,若legend中有輸入框,則此輸入框是無(wú)法被禁用的。

eg:

<form role="form">
    <fieldset disabled>
        <legend><input type="text" class="form-control" placeholder="我沒(méi)被禁用" /></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">無(wú)法選擇
            </label>
        </div>
        <button type="submit" class="btnbtn-primary">提交</button>
  </fieldset>
</form>

效果圖如下所示:

bootstrap可對(duì)表單設(shè)置的狀態(tài)有哪些

三、驗(yàn)證狀態(tài):該狀態(tài)告訴用戶,他們的操作是否正確

在Bootstrap中提供3種驗(yàn)證狀態(tài)樣式:

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

② .has-error : 錯(cuò)誤狀態(tài)(紅色)

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

使用方法:在form-group容器上添加對(duì)應(yīng)的狀態(tài)類名即可。

eg:

<form role="form">
    <div class="form-group has-success">
        <label class="control-label" for="inputSuccess1">成功狀態(tài)</label>
        <input type="text" class="form-control" id="inputSuccess1" placeholder="成功狀態(tài)" >
    </div>
    <div class="form-group has-warning">
        <label class="control-label" for="inputWarning1">警告狀態(tài)</label>
        <input type="text" class="form-control" id="inputWarning1" placeholder="警告狀態(tài)">
    </div>
    <div class="form-group has-error">
        <label class="control-label" for="inputError1">錯(cuò)誤狀態(tài)</label>
        <input type="text" class="form-control" id="inputError1" placeholder="錯(cuò)誤狀態(tài)">
    </div>
</form>

說(shuō)明:從效果可看出,三種樣式除了顏色不同外,效果都一樣。

在Bootstrap的表單驗(yàn)證中,不同狀態(tài)會(huì)提供不同的icon,如成功是個(gè)對(duì)號(hào)"√",錯(cuò)誤是個(gè)叉號(hào)"×"等。

若想讓表單在不同狀態(tài)下顯示對(duì)應(yīng)的icon,則只需在對(duì)應(yīng)狀態(tài)下添加類名"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">成功狀態(tài)</label>
        <input type="text" class="form-control" id="inputSuccess" placeholder="成功狀態(tài)" >
        <span class="glyphicon glyphicon-ok form-control-feedback"></span>
    </div>
    <div class="form-group has-warning has-feedback">
        <label class="control-label" for="inputWarning">警告狀態(tài)</label>
        <input type="text" class="form-control" id="inputWarning" placeholder="警告狀態(tài)" >
        <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">錯(cuò)誤狀態(tài)</label>
        <input type="text" class="form-control" id="inputError" placeholder="錯(cuò)誤狀態(tài)" >
        <span class="glyphicon glyphicon-remove form-control-feedback"></span>
  </div>
</form>

效果如下所示:

bootstrap可對(duì)表單設(shè)置的狀態(tài)有哪些

說(shuō)明:從效果圖中可看出,圖標(biāo)都居右。

注:Bootstrap中的圖標(biāo)都是使用@face-face來(lái)制作,且必須在表單中添加個(gè)span元素來(lái)實(shí)現(xiàn)。

eg:

<span class="glyphicon glyphicon-remove form-control-feedback"></span>

感謝各位的閱讀,以上就是“bootstrap可對(duì)表單設(shè)置的狀態(tài)有哪些”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)bootstrap可對(duì)表單設(shè)置的狀態(tài)有哪些這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI