表單是網頁收集資料的核心工具。以下整理最常見的表單寫法與元素類型。
表單的基本結構如下:
<form action="url" method="get/post" name="#"> <input type="*" name=" " /> </form>
其中 input 的 type 常用值包括:
text:一般文字輸入,如姓名。password:密碼輸入。submit:提交按鈕。reset:重置按鈕。image:以圖片作為按鈕,需搭配 src 屬性。checkbox:複選框。radio:單選框。file:上傳檔案。hidden:隱藏欄位,可向伺服器提交內容但不影響畫面。下拉選單的寫法:
<select> <option value="#">..... </option> <option value="#">..... </option> </select>
多行文字輸入域的寫法:
<textarea>.....</textarea>
把這些元素放進 form 標籤之間,就完成了一個基本的表單。