HTML <form> 標籤
示例
一個包含兩個輸入欄位和一個提交按鈕的 HTML 表單
<form action="/action_page.php" method="get">
<label for="fname">名:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">姓氏:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="提交">
</form>
自己動手試一試 »
更多“自己嘗試”的例子見下文。
定義和用法
The <form> tag is used to create an HTML form for user input.
The <form> element can contain one or more of the following form elements
瀏覽器支援
| 元素 | |||||
|---|---|---|---|---|---|
| <form> | 是 | 是 | 是 | 是 | 是 |
屬性
| Attribute | 值 | 描述 |
|---|---|---|
| accept-charset | character_set | Specifies the character encodings that are to be used for the form submission |
| action | URL | 指定提交表單資料時傳送到的位置 |
| autocomplete | on off |
Specifies whether a form should have autocomplete on or off |
| enctype | application/x-www-form-urlencoded multipart/form-data text/plain |
指定提交表單資料時如何進行編碼(僅適用於 method="post") |
| method | dialog get post |
指定傳送表單資料時要使用的 HTTP 方法 |
| name | text | Specifies the name of a form |
| novalidate | novalidate | 指定提交表單時不對錶單進行驗證 |
| rel | external 幫助 license next nofollow noopener noreferrer opener prev search |
Specifies the relationship between a linked resource and the current document |
| target | _blank _self _parent _top |
Specifies where to display the response that is received after submitting the form |
全域性屬性
The <form> tag also supports the Global Attributes in HTML.
事件屬性
The <form> tag also supports the Event Attributes in HTML.
更多示例
示例
一個包含複選框的 HTML 表單
<form action="/action_page.php" method="get">
<input type="checkbox" name="vehicle1" value="Bike">
<label for="vehicle1"> 我有一輛腳踏車</label><br>
<input type="checkbox" name="vehicle2" value="Car">
<label for="vehicle2"> 我有一輛汽車</label><br>
<input type="checkbox" name="vehicle3" value="Boat" checked>
<label for="vehicle3"> I have a boat</label><br><br>
<input type="submit" value="提交">
</form>
自己動手試一試 »
示例
一個包含單選按鈕的 HTML 表單
<form action="/action_page.php" method="get">
<input type="radio" id="html" name="fav_language" value="HTML">
<label for="html">HTML</label><br>
<input type="radio" id="css" name="fav_language" value="CSS" checked="checked">
<label for="css">CSS</label><br>
<input type="radio" id="javascript" name="fav_language" value="JavaScript">
<label for="javascript">JavaScript</label><br><br>
<input type="submit" value="提交">
</form>
自己動手試一試 »
相關頁面
HTML 教程: HTML 表單與輸入
HTML DOM 參考: Form 物件
CSS 教程: 表單樣式
預設 CSS 設定
Most browsers will display the <form> element with the following default values