在網頁中,表單(Form)通常用來收集使用者資料,例如註冊帳號、登入、送出聯絡資訊。表單的基礎是 標籤,裡面放各種輸入元件。
HTML
<form action="/submit" method="POST">
<label for="username">帳號:</label>
<input type="text" id="username" name="username" required>
<label for="password">密碼:</label>
<input type="password" id="password" name="password" required>
<button type="submit">送出</button>
</form>
action:送出表單要去哪裡(通常是後端 API)
method:GET 或 POST
name:表單送出時的欄位名稱
required:必填檢查
HTML
<input type="email" placeholder="輸入 Email">
<input type="number" min="1" max="10">
<input type="checkbox" id="agree"> 我同意條款
<input type="radio" name="gender" value="male"> 男
<input type="radio" name="gender" value="female"> 女
<select>
<option value="tw">台灣</option>
<option value="jp">日本</option>
</select>
<textarea rows="4" placeholder="留言..."></textarea>
👉 表單元件有很多種,選擇要符合需求。
(例:年齡用 number,留言用 textarea)