表單是 Web 互動核心,XHTML 嚴格規範標籤結構與屬性。本文涵蓋 <form> 容器、<input> 兩大基礎類型(文字/密碼)、無障礙屬性與後端銜接概念。
<form action="/submit" method="post" id="login-form"> <!-- 表單控件 --> </form>
| 屬性 | 說明 | 常用值 |
|---|---|---|
action | 提交目標 URL | 相對/絕對路徑 |
method | HTTP 方法 | get (查詢)、post (異動) |
enctype | 編碼類型 | application/x-www-form-urlencoded (預設)、multipart/form-data (檔案上傳) |
id/name | 表單識別碼 | JS 選取/提交參考 |
<label for="username">姓名:</label> <input type="text" id="username" name="user" placeholder="請輸入姓名" required />
<label for="password">密碼:</label> <input type="password" id="password" name="pass" autocomplete="current-password" />
for 對應 id,點擊文字聚焦控件<input /> 符合 XHTMLtype="radio":單選群組(同 name)type="checkbox":多選/布林type="submit/reset/button":提交/重置/自定義按鈕<select><option>:下拉選單<textarea>:多行文字<fieldset><legend>:分組語意化(詳見 ID 35018)