HTML 表單是網頁互動的核心,用於蒐集使用者輸入資料。本文透過完整的註冊表單範例,詳細展示各類表單元素的寫法與屬性設定。
<form action="DoFormAction.htm">
<fieldset style="width=800px">
<legend>請輸入以下的信息然後進行註冊</legend>
<table cellspacing="0px" cellpadding="6px" border="1px" bordercolor="black" align="center" width="600px">
... 表單欄位 ...
</table>
</fieldset>
</form>
<input type="text" size="20" style="width:150px" /><input type="password" size="20" style="width:150px" />name 屬性,搭配 value 区分值,可用 checked 預選<label for="id"> 讓點擊文字也能選擇單選項<select> 包含 <option>,可用 selected 預設值<optgroup label="群組名"> 實現選項分類<select size="3" multiple="multiple"> 允許多選name 分組,可多選<input type="file" name="myPic" /><textarea rows="5" cols="50"></textarea><input type="submit" value="確定" /> - 提交表單<input type="reset" value="清空" /> - 重置表單<input type="image" src="..." onclick="..." /> - 圖片按鈕(同樣會提交資料)文章另附簡易 JavaScript 函數 show_page(num),示範點擊圖片彈出產品名稱並跳轉頁面的邏輯。