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