
- Bootstrap 教程
- Bootstrap - 首頁
- Bootstrap - 概述
- Bootstrap - 環境設定
- Bootstrap - 從右到左 (RTL)
- Bootstrap - CSS 變數
- Bootstrap - 色彩模式
- Bootstrap 佈局
- Bootstrap - 斷點
- Bootstrap - 容器
- Bootstrap - 網格系統
- Bootstrap - 列
- Bootstrap - 溝槽
- Bootstrap - 實用工具
- Bootstrap - CSS 網格
- Bootstrap 元件
- Bootstrap - 手風琴
- Bootstrap - 警報
- Bootstrap - 徽章
- Bootstrap - 麵包屑
- Bootstrap - 按鈕
- Bootstrap - 按鈕組
- Bootstrap - 卡片
- Bootstrap - 走馬燈
- Bootstrap - 關閉按鈕
- Bootstrap - 摺疊
- Bootstrap - 下拉選單
- Bootstrap - 列表組
- Bootstrap - 模態框
- Bootstrap - 導航欄
- Bootstrap - 導航和選項卡
- Bootstrap - 畫布側邊欄
- Bootstrap - 分頁
- Bootstrap - 佔位符
- Bootstrap - 氣泡提示
- Bootstrap - 進度條
- Bootstrap - 滾動偵測
- Bootstrap - 載入動畫
- Bootstrap - 吐司提示
- Bootstrap - 工具提示
- Bootstrap 表單
- Bootstrap - 表單
- Bootstrap - 表單控制元件
- Bootstrap - 選擇框
- Bootstrap - 複選框和單選按鈕
- Bootstrap - 範圍滑塊
- Bootstrap - 輸入組
- Bootstrap - 浮動標籤
- Bootstrap - 佈局
- Bootstrap - 驗證
- Bootstrap 輔助類
- Bootstrap - 清除浮動
- Bootstrap - 顏色和背景
- Bootstrap - 彩色連結
- Bootstrap - 聚焦環
- Bootstrap - 圖示連結
- Bootstrap - 定位
- Bootstrap - 比例
- Bootstrap - 堆疊
- Bootstrap - 拉伸連結
- Bootstrap - 文字截斷
- Bootstrap - 垂直線
- Bootstrap - 視覺隱藏
- Bootstrap 實用工具
- Bootstrap - 背景
- Bootstrap - 邊框
- Bootstrap - 顏色
- Bootstrap - 顯示
- Bootstrap - Flexbox
- Bootstrap - 浮動
- Bootstrap - 互動
- Bootstrap - 連結
- Bootstrap - 物件適配
- Bootstrap - 不透明度
- Bootstrap - 溢位
- Bootstrap - 定位
- Bootstrap - 陰影
- Bootstrap - 大小
- Bootstrap - 間距
- Bootstrap - 文字
- Bootstrap - 垂直對齊
- Bootstrap - 可見性
- Bootstrap 演示
- Bootstrap - 網格演示
- Bootstrap - 按鈕演示
- Bootstrap - 導航演示
- Bootstrap - 部落格演示
- Bootstrap - 滑塊演示
- Bootstrap - 走馬燈演示
- Bootstrap - 標題演示
- Bootstrap - 頁尾演示
- Bootstrap - 英雄區域演示
- Bootstrap - 特色區域演示
- Bootstrap - 側邊欄演示
- Bootstrap - 下拉選單演示
- Bootstrap - 列表組演示
- Bootstrap - 模態框演示
- Bootstrap - 徽章演示
- Bootstrap - 麵包屑演示
- Bootstrap - 超大標題演示
- Bootstrap-粘性頁尾演示
- Bootstrap-相簿演示
- Bootstrap-登入演示
- Bootstrap-定價演示
- Bootstrap-結賬演示
- Bootstrap-產品演示
- Bootstrap-封面演示
- Bootstrap-儀表盤演示
- Bootstrap-粘性頁尾導航欄演示
- Bootstrap-砌體佈局演示
- Bootstrap-啟動模板演示
- Bootstrap-相簿 RTL 演示
- Bootstrap-結賬 RTL 演示
- Bootstrap-走馬燈 RTL 演示
- Bootstrap-部落格 RTL 演示
- Bootstrap-儀表盤 RTL 演示
- Bootstrap 有用資源
- Bootstrap - 問答
- Bootstrap - 快速指南
- Bootstrap - 有用資源
- Bootstrap - 討論
Bootstrap - 表單
本章將討論 Bootstrap 表單。表單允許使用者輸入資料,例如姓名、電子郵件地址、密碼等,然後可以傳送到伺服器進行處理。Bootstrap 提供了類來建立各種樣式、佈局和自定義元件的表單。
基本表單
Bootstrap 中的表單控制元件擴充套件了 重置的表單樣式,並使用了類。為了在不同瀏覽器和裝置上實現一致的渲染和自定義顯示,請使用這些類。
要使用更新的輸入控制元件,例如電子郵件驗證、數字選擇和其他功能,請確保在所有輸入元素上使用適當的 type 屬性(例如,電子郵件地址使用 email 或數值資料使用 number)。
以下示例演示了 Bootstrap 的基本表單。
示例
您可以使用 編輯和執行 選項編輯並嘗試執行此程式碼。
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap - Form</title> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script> </head> <body> <form> <div class="mb-3"> <label for=" sampleInputEmail" class="form-label">Username</label> <input type="email" class="form-control" id=" sampleInputEmail" aria-describedby="emailHelp"> </div> <div class="mb-3"> <label for="sampleInputPassword" class="form-label">Password</label> <input type="password" class="form-control" id="sampleInputPassword"> </div> <div class="mb-3 form-check"> <input type="checkbox" class="form-check-input" id="sampleCheck"> <label class="form-check-label" for="sampleCheck">Remember me</label> </div> <button type="submit" class="btn btn-primary">Log in</button> </form> </body> </html>
停用表單
要阻止使用者互動並使輸入看起來更淺,請使用 disabled 布林屬性。
要停用 <fieldset> 中的所有控制元件,請新增 disabled 屬性。瀏覽器將把包含在 fieldset <disabled> 中的原生表單控制元件的 <input>、<select> 和 <button> 元素都視為已停用,從而阻止鍵盤和滑鼠與它們進行互動。
如果表單具有自定義按鈕式元素,例如 <a class="btn btn-*">...</a>,則它們設定了 pointer-events: none,這意味著它們仍然可聚焦和鍵盤操作。要阻止它們接收焦點,請使用 tabindex="-1",並使用 aria-disabled="disabled" 向輔助技術發出其狀態訊號。
示例
您可以使用 編輯和執行 選項編輯並嘗試執行此程式碼。
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap - Form</title> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script> </head> <body> <form> <fieldset disabled> <div class="mb-3"> <label for="disabledEmailInput" class="form-label">Disabled Input</label> <input type="text" id="disabledEmailInput" class="form-control" placeholder="Email Id"> </div> <div class="mb-3"> <label for="disabledPasswordInput" class="form-label">Disabled Input</label> <select id="disabledPasswordInput" class="form-select"> <option>Password</option> </select> </div> <div class="mb-3"> <div class="form-check"> <input class="form-check-input" type="checkbox" id="disabledcheckbox" disabled> <label class="form-check-label" for="disabledcheckbox"> Disabled Check Box </label> </div> </div> <button type="submit" class="btn btn-primary">Disabled Button</button> </fieldset> </form> </body> </html>
可訪問性
每個表單控制元件都具有輔助技術使用者可以訪問的適當名稱。使用標籤元素或 <button>...</button> 中的描述性文字是最簡單的實現方法。
當沒有提供可見的“標籤”或適當的文字內容時,請使用其他方法獲取可訪問的名稱,例如
使用類 .visually-hidden 隱藏 <label> 元素。
使用 aria-labelledby 指向充當 <label> 的現有元素。
包含 title 屬性。
使用 aria-label 設定元素的可訪問名稱。
當這些方法都不可用時,輔助技術會使用 placeholder 屬性作為 <input> 和 <textarea> 元素的可訪問名稱的後備。
使用視覺隱藏內容將有助於輔助技術使用者,但是某些使用者仍然可能在缺少可見標籤文字時遇到問題。