欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

如何使用Bootstrap創(chuàng)建表單

 更新時(shí)間:2017年03月29日 14:08:17   作者:Carl_Hugo  
在本章中,我們將學(xué)習(xí)如何使用 Bootstrap 創(chuàng)建表單。Bootstrap 通過一些簡(jiǎn)單的 HTML 標(biāo)簽和擴(kuò)展的類即可創(chuàng)建出不同樣式的表單

Bootstrap 表單

在本章中,我們將學(xué)習(xí)如何使用 Bootstrap 創(chuàng)建表單。Bootstrap 通過一些簡(jiǎn)單的 HTML 標(biāo)簽和擴(kuò)展的類即可創(chuàng)建出不同樣式的表單。

垂直或基本表單

基本的表單結(jié)構(gòu)是 Bootstrap 自帶的,個(gè)別的表單控件自動(dòng)接收一些全局樣式。下面列出了創(chuàng)建基本表單的步驟:

- 向父 <form> 元素添加 role=”form”。

- 把標(biāo)簽和控件放在一個(gè)帶有 class .form-group 的

中。這是獲取最佳間距所必需的。

- 向所有的文本元素 <input>、<textarea> 和 <select> 添加 class .form-control。

<form role="form">
 <div class="form-group">
 <label for="name">名稱</label>
 <input type="text" class="form-control" id="name" placeholder="請(qǐng)輸入名稱">
 </div>
 <div class="form-group">
 <label for="inputfile">文件輸入</label>
 <input type="file" id="inputfile">
 <p class="help-block">這里是塊級(jí)幫助文本的實(shí)例。</p>
 </div>
 <div class="checkbox">
 <label>
  <input type="checkbox">請(qǐng)打勾
 </label>
 </div>
 <button type="submit" class="btn btn-default">提交</button>
</form>

效果

內(nèi)聯(lián)表單

如果需要?jiǎng)?chuàng)建一個(gè)表單,它的所有元素是內(nèi)聯(lián)的,向左對(duì)齊的,標(biāo)簽是并排的,請(qǐng)向 <form>標(biāo)簽添加 class .form-inline。

<form class="form-inline" role="form">
 <div class="form-group">
 <label class="sr-only" for="name">名稱</label>
 <input type="text" class="form-control" id="name" placeholder="請(qǐng)輸入名稱">
 </div>
 <div class="form-group">
 <label class="sr-only" for="inputfile">文件輸入</label>
 <input type="file" id="inputfile">
 </div>
 <div class="checkbox">
 <label>
  <input type="checkbox">請(qǐng)打勾
 </label>
 </div>
 <button type="submit" class="btn btn-default">提交</button>
</form>

 

- 默認(rèn)情況下,Bootstrap 中的 input、select 和 textarea 有 100% 寬度。在使用內(nèi)聯(lián)表單時(shí),您需要在表單控件上設(shè)置一個(gè)寬度。

- 使用 class .sr-only,您可以隱藏內(nèi)聯(lián)表單的標(biāo)簽。

水平表單

水平表單與其他表單不僅標(biāo)記的數(shù)量上不同,而且表單的呈現(xiàn)形式也不同。如需創(chuàng)建一個(gè)水平布局的表單,請(qǐng)按下面的幾個(gè)步驟進(jìn)行:

- 向父 <form> 元素添加 class .form-horizontal。
- 把標(biāo)簽和控件放在一個(gè)帶有 class .form-group 的<div> 中。
- 向標(biāo)簽添加 class .control-label。

<form class="form-horizontal" role="form">
 <div class="form-group">
 <label for="firstname" class="col-sm-2 control-label">名字</label>
 <div class="col-sm-10">
  <input type="text" class="form-control" id="firstname" placeholder="請(qǐng)輸入名字">
 </div>
 </div>
 <div class="form-group">
 <label for="lastname" class="col-sm-2 control-label">姓</label>
 <div class="col-sm-10">
  <input type="text" class="form-control" id="lastname" placeholder="請(qǐng)輸入姓">
 </div>
 </div>
 <div class="form-group">
 <div class="col-sm-offset-2 col-sm-10">
  <div class="checkbox">
  <label>
   <input type="checkbox">請(qǐng)記住我
  </label>
  </div>
 </div>
 </div>
 <div class="form-group">
 <div class="col-sm-offset-2 col-sm-10">
  <button type="submit" class="btn btn-default">登錄</button>
 </div>
 </div>
</form>

效果

支持的表單控件

Bootstrap 支持最常見的表單控件,主要是 input、textarea、checkbox、radio 和 select。

輸入框(Input)

最常見的表單文本字段是輸入框 input。用戶可以在其中輸入大多數(shù)必要的表單數(shù)據(jù)。Bootstrap 提供了對(duì)所有原生的 HTML5 的 input 類型的支持,包括:text、password、datetime、datetime-local、date、month、time、week、number、email、url、search、tel 和 color。適當(dāng)?shù)?type 聲明是必需的,這樣才能讓 input 獲得完整的樣式。

<form role="form">
 <div class="form-group">
 <label for="name">標(biāo)簽</label>
 <input type="text" class="form-control" placeholder="文本輸入">
 </div>
 </form>

效果

文本框(Textarea)

當(dāng)您需要進(jìn)行多行輸入的時(shí),則可以使用文本框 textarea。必要時(shí)可以改變 rows 屬性(較少的行 = 較小的盒子,較多的行 = 較大的盒子)。

<form role="form">
 <div class="form-group">
 <label for="name">文本框</label>
 <textarea class="form-control" rows="3"></textarea>
 </div>
</form>

復(fù)選框(Checkbox)和單選框(Radio)

復(fù)選框和單選按鈕用于讓用戶從一系列預(yù)設(shè)置的選項(xiàng)中進(jìn)行選擇。

- 當(dāng)創(chuàng)建表單時(shí),如果您想讓用戶從列表中選擇若干個(gè)選項(xiàng)時(shí),請(qǐng)使用 checkbox。如果您限制用戶只能選擇一個(gè)選項(xiàng),請(qǐng)使用 radio。

- 對(duì)一系列復(fù)選框和單選框使用 .checkbox-inline 或 .radio-inline class,控制它們顯示在同一行上。

下面的實(shí)例演示了這兩種類型(默認(rèn)和內(nèi)聯(lián)):

<label for="name">默認(rèn)的復(fù)選框和單選按鈕的實(shí)例</label>
<div class="checkbox">
 <label>
 <input type="checkbox" value="">選項(xiàng) 1
 </label>
</div>
<div class="checkbox">
 <label>
 <input type="checkbox" value="">選項(xiàng) 2
 </label>
</div>
<div class="radio">
 <label>
 <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>選項(xiàng) 1
 </label>
</div>
<div class="radio">
 <label>
 <input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">選項(xiàng) 2 - 選擇它將會(huì)取消選擇選項(xiàng) 1
 </label>
</div>
<label for="name">內(nèi)聯(lián)的復(fù)選框和單選按鈕的實(shí)例</label>
<div>
 <label class="checkbox-inline">
 <input type="checkbox" id="inlineCheckbox1" value="option1">選項(xiàng) 1
 </label>
 <label class="checkbox-inline">
 <input type="checkbox" id="inlineCheckbox2" value="option2">選項(xiàng) 2
 </label>
 <label class="checkbox-inline">
 <input type="checkbox" id="inlineCheckbox3" value="option3">選項(xiàng) 3
 </label>
 <label class="checkbox-inline">
 <input type="radio" name="optionsRadiosinline" id="optionsRadios3" value="option1" checked>選項(xiàng) 1
 </label>
 <label class="checkbox-inline">
 <input type="radio" name="optionsRadiosinline" id="optionsRadios4" value="option2">選項(xiàng) 2
 </label>
</div>

效果

選擇框(Select)

當(dāng)您想讓用戶從多個(gè)選項(xiàng)中進(jìn)行選擇,但是默認(rèn)情況下只能選擇一個(gè)選項(xiàng)時(shí),則使用選擇框。

使用 <select> 展示列表選項(xiàng),通常是那些用戶很熟悉的選擇列表,比如州或者數(shù)字。

使用 multiple=”multiple” 允許用戶選擇多個(gè)選項(xiàng)。

下面的實(shí)例演示了這兩種類型(select 和 multiple):

<form role="form">
 <div class="form-group">
 <label for="name">選擇列表</label>
 <select class="form-control">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
 </select>
 <label for="name">可多選的選擇列表</label>
 <select multiple class="form-control">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
 </select>
 </div>
</form>

效果

靜態(tài)控件

當(dāng)您需要在一個(gè)水平表單內(nèi)的表單標(biāo)簽后放置純文本時(shí),請(qǐng)?jiān)?<p> 上使用 class .form-control-static。

<form class="form-horizontal" role="form">
 <div class="form-group">
 <label class="col-sm-2 control-label">Email</label>
 <div class="col-sm-10">
  <p class="form-control-static">email@example.com</p>
 </div>
 </div>
 <div class="form-group">
 <label for="inputPassword" class="col-sm-2 control-label">密碼</label>
 <div class="col-sm-10">
  <input type="password" class="form-control" id="inputPassword" placeholder="請(qǐng)輸入密碼">
 </div>
 </div>
</form>

效果

表單控件狀態(tài)

除了 :focus 狀態(tài)(即,用戶點(diǎn)擊 input 或使用 tab 鍵聚焦到 input 上),Bootstrap 還為禁用的輸入框定義了樣式,并提供了表單驗(yàn)證的 class。

輸入框焦點(diǎn)

當(dāng)輸入框 input 接收到 :focus 時(shí),輸入框的輪廓會(huì)被移除,同時(shí)應(yīng)用 box-shadow。

禁用的輸入框 input

如果您想要禁用一個(gè)輸入框 input,只需要簡(jiǎn)單地添加 disabled 屬性,這不僅會(huì)禁用輸入框,還會(huì)改變輸入框的樣式以及當(dāng)鼠標(biāo)的指針懸停在元素上時(shí)鼠標(biāo)指針的樣式。

禁用的字段集 fieldset

對(duì) <fieldset> 添加 disabled 屬性來禁用 <fieldset> 內(nèi)的所有控件。

驗(yàn)證狀態(tài)

Bootstrap 包含了錯(cuò)誤、警告和成功消息的驗(yàn)證樣式。只需要對(duì)父元素簡(jiǎn)單地添加適當(dāng)?shù)?class(.has-warning、 .has-error 或 .has-success)即可使用驗(yàn)證狀態(tài)。

下面的實(shí)例演示了所有控件狀態(tài):

<form class="form-horizontal" role="form">
 <div class="form-group">
 <label class="col-sm-2 control-label">聚焦</label>
 <div class="col-sm-10">
  <input class="form-control" id="focusedInput" type="text" value="該輸入框獲得焦點(diǎn)...">
 </div>
 </div>
 <div class="form-group">
 <label for="inputPassword" class="col-sm-2 control-label">禁用</label>
 <div class="col-sm-10">
  <input class="form-control" id="disabledInput" type="text" placeholder="該輸入框禁止輸入..." disabled>
 </div>
 </div>
 <fieldset disabled>
 <div class="form-group">
  <label for="disabledTextInput" class="col-sm-2 control-label">禁用輸入(Fieldset disabled)</label>
  <div class="col-sm-10">
  <input type="text" id="disabledTextInput" class="form-control" placeholder="禁止輸入">
  </div>
 </div>
 <div class="form-group">
  <label for="disabledSelect" class="col-sm-2 control-label">禁用選擇菜單(Fieldset disabled)</label>
  <div class="col-sm-10">
  <select id="disabledSelect" class="form-control">
   <option>禁止選擇</option>
  </select>
  </div>
 </div>
 </fieldset>
 <div class="form-group has-success">
 <label class="col-sm-2 control-label" for="inputSuccess">輸入成功</label>
 <div class="col-sm-10">
  <input type="text" class="form-control" id="inputSuccess">
 </div>
 </div>
 <div class="form-group has-warning">
 <label class="col-sm-2 control-label" for="inputWarning">輸入警告</label>
 <div class="col-sm-10">
  <input type="text" class="form-control" id="inputWarning">
 </div>
 </div>
 <div class="form-group has-error">
 <label class="col-sm-2 control-label" for="inputError">輸入錯(cuò)誤</label>
 <div class="col-sm-10">
  <input type="text" class="form-control" id="inputError">
 </div>
 </div>
</form>

效果

表單控件大小

您可以分別使用 class .input-lg 和 .col-lg-* 來設(shè)置表單的高度和寬度。下面的實(shí)例演示了這點(diǎn):

<form role="form">
 <div class="form-group">
 <input class="form-control input-lg" type="text" placeholder=".input-lg">
 </div>
 <div class="form-group">
 <input class="form-control" type="text" placeholder="默認(rèn)輸入">
 </div>
 <div class="form-group">
 <input class="form-control input-sm" type="text" placeholder=".input-sm">
 </div>
 <div class="form-group"></div>
 <div class="form-group">
 <select class="form-control input-lg">
  <option value="">.input-lg</option>
 </select>
 </div>
 <div class="form-group">
 <select class="form-control">
  <option value="">默認(rèn)選擇</option>
 </select>
 </div>
 <div class="form-group">
 <select class="form-control input-sm">
  <option value="">.input-sm</option>
 </select>
 </div>
 <div class="row">
 <div class="col-lg-2">
  <input type="text" class="form-control" placeholder=".col-lg-2">
 </div>
 <div class="col-lg-3">
  <input type="text" class="form-control" placeholder=".col-lg-3">
 </div>
 <div class="col-lg-4">
  <input type="text" class="form-control" placeholder=".col-lg-4">
 </div>
 </div>
</form>

效果

表單幫助文本

Bootstrap 表單控件可以在輸入框 input 上有一個(gè)塊級(jí)幫助文本。為了添加一個(gè)占用整個(gè)寬度的內(nèi)容塊,請(qǐng)?jiān)?<input> 后使用 .help-block。下面的實(shí)例演示了這點(diǎn):

<form role="form">
 <span>幫助文本實(shí)例</span>
 <input class="form-control" type="text" placeholder="">
 <span class="help-block">一個(gè)較長(zhǎng)的幫助文本塊,超過一行,
 需要擴(kuò)展到下一行。本實(shí)例中的幫助文本總共有兩行。</span>
</form>

以上所述是小編給大家介紹的使用Bootstrap創(chuàng)建表單的方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Javascript中常用類型的格式化方法小結(jié)

    Javascript中常用類型的格式化方法小結(jié)

    這篇文章主要給大家介紹了Javascript中常用類型的格式化方法,其中包括格式化浮點(diǎn)數(shù)、格式化有符號(hào)整數(shù)(int32)、格式化無符號(hào)整數(shù)(uint32)、格式化布爾值以及格式化字符串等,文中給出了詳細(xì)的示例代碼,有需要的朋友們可以參考借鑒,下面來一起看看吧。
    2016-12-12
  • 探討js中的雙感嘆號(hào)判斷

    探討js中的雙感嘆號(hào)判斷

    js中的雙感嘆號(hào)判斷。在網(wǎng)上查了些資料,他相當(dāng)于三元運(yùn)算符,返回boolean值
    2013-11-11
  • WebSocket的通信過程與實(shí)現(xiàn)方法詳解

    WebSocket的通信過程與實(shí)現(xiàn)方法詳解

    這篇文章主要給大家愛介紹了關(guān)于WebSocket的通信過程與實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧
    2018-04-04
  • 淺談JavaScript工具鏈不完全指南

    淺談JavaScript工具鏈不完全指南

    經(jīng)過這么多年的發(fā)展,JavaScript 早已經(jīng)不是當(dāng)年那個(gè)不太起眼的腳本語言。如今的 JavaScript 可以說是風(fēng)光無限,在 Web 前端、移動(dòng)端、服務(wù)端甚至物聯(lián)網(wǎng)設(shè)備上都大展身手,到處都有它的身影。
    2021-05-05
  • JS庫之wow.js使用方法

    JS庫之wow.js使用方法

    近日,在做項(xiàng)目中,需要做到滾動(dòng)條滑到某個(gè)位置時(shí),才能顯示動(dòng)畫,網(wǎng)上查詢到有個(gè)wow.js可以達(dá)到要求,現(xiàn)在把使用方法做如下總結(jié),需要的朋友參考下吧
    2017-09-09
  • 微信小程序wx.getImageInfo()如何獲取圖片信息

    微信小程序wx.getImageInfo()如何獲取圖片信息

    這篇文章主要為大家詳細(xì)介紹了微信小程序wx.getImageInfo()如何獲取圖片信息,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • 防止頁面url緩存中ajax中post請(qǐng)求的處理方法

    防止頁面url緩存中ajax中post請(qǐng)求的處理方法

    這篇文章主要介紹了防止頁面url緩存中ajax中post請(qǐng)求的處理方式的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下
    2017-10-10
  • js加載讀取內(nèi)容及顯示與隱藏div示例

    js加載讀取內(nèi)容及顯示與隱藏div示例

    這篇文章主要介紹了js加載讀取內(nèi)容及顯示與隱藏div的方法,需要的朋友可以參考下
    2014-02-02
  • JavaScript判斷按鈕被點(diǎn)擊的方法

    JavaScript判斷按鈕被點(diǎn)擊的方法

    javascript代碼判斷按鈕是否被點(diǎn)擊了在項(xiàng)目中經(jīng)常會(huì)遇到這個(gè)需求,今天小編抽點(diǎn)時(shí)間給大家分享一段代碼關(guān)于javascript判斷按鈕是否被點(diǎn)擊的方法,感興趣的朋友一起學(xué)習(xí)吧
    2015-12-12
  • JS實(shí)現(xiàn)的DOM插入節(jié)點(diǎn)操作示例

    JS實(shí)現(xiàn)的DOM插入節(jié)點(diǎn)操作示例

    這篇文章主要介紹了JS實(shí)現(xiàn)的DOM插入節(jié)點(diǎn)操作,結(jié)合實(shí)例形式分析了javascript針對(duì)頁面dom元素動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2018-04-04

最新評(píng)論