导航
×
   ❮   
HTML CSS JavaScript PHP Go Sass W3C Colors ECMS

HTML 参考手册

HTML 元素(功能排序) HTML 浏览器支持 HTML 属性 HTML 全局属性 HTML 事件 HTML 颜色 HTML 画布 HTML 音频/视频 HTML 字符集 HTML 文档类型 HTML URL 编码 HTML 语言代码 HTML 国家代码 HTTP 状态消息 HTTP 请求方法 PX-EM 转换 键盘快捷键

HTML 标签

<!--> <!DOCTYPE> <a> <abbr> <acronym> <address> <applet> <area> <article> <aside> <audio> <b> <base> <basefont> <bdi> <bdo> <big> <blockquote> <body> <br> <button> <canvas> <caption> <center> <cite> <code> <col> <colgroup> <data> <datalist> <dd> <del> <details> <dfn> <dialog> <dir> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <font> <footer> <form> <frame> <frameset> <h1> - <h6> <head> <header> <hr> <html> <i> <iframe> <img> <input> <ins> <kbd> <label> <legend> <li> <link> <main> <map> <mark> <meta> <meter> <nav> <noframes> <noscript> <object> <ol> <optgroup> <option> <output> <p> <param> <picture> <pre> <progress> <q> <rp> <rt> <ruby> <s> <samp> <script> <section> <select> <small> <source> <span> <strike> <strong> <style> <sub> <summary> <sup> <svg> <table> <tbody> <td> <template> <textarea> <tfoot> <th> <thead> <time> <title> <tr> <track> <tt> <u> <ul> <var> <video> <wbr>

HTML <form> 标签


实例

包含两个输入字段和一个提交按钮的 HTML 表单:

   <form     action="/action_page.asp"    method="get">
 <label for="fname">First name:</label>
 <input type="text" id="fname"     name="fname"><br><br>
 <label for="lname">Last name:</label>
     <input type="text" id="lname" name="lname"><br><br>
 <input     type="submit" value="提交">
   </form>
亲自试一试 »

下面有更多实例。


定义和用法

<form> 标签用于为用户输入创建 HTML 表单。

<form> 元素可以包含以下一个或多个表单元素:


浏览器支持

元素          
<form> Yes Yes Yes Yes Yes

属性

属性 描述
accept-charset character_set 规定服务器可处理的表单数据字符集。
action URL 规定当提交表单时向何处发送表单数据。
autocomplete on
off
规定是否启用表单的自动完成功能。
enctype application/x-www-form-urlencoded
multipart/form-data
text/plain
规定在发送表单数据之前如何对其进行编码。
method get
post
规定用于发送 form-data 的 HTTP 方法。
name text 规定表单的名称。
novalidate novalidate 如果使用该属性,则提交表单时不进行验证。
rel external
help
license
next
nofollow
noopener
noreferrer
opener
prev
search
规定链接资源和当前文档之间的关系。
target _blank
_self
_parent
_top
规定在何处打开 action URL。

全局属性

<form> 标签支持 HTML 中的全局属性


事件属性

<form> 标签支持 HTML 中的事件属性


更多实例

实例

带有复选框的表单:

<form action="/action_page.asp" 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"> 我有一条船</label><br><br>
 <input type="submit" value="提交">
   </form>
亲自试一试 »

实例

带有单选按钮的表单:

<form action="/action_page.asp" method="get">
 <input type="radio"     id="male" name="gender" value="male">
 <label     for="male">Male</label><br>
 <input type="radio" id="female"     name="gender" value="female" checked="checked">
 <label     for="female">Female</label><br>
 <input type="radio" id="other"     name="gender" value="other">
 <label for="other">Other</label><br><br>
     <input type="submit" value="提交">
</form>
亲自试一试 »

相关页面

HTML 教程: HTML Forms 和 Input

HTML DOM 参考手册: Form 对象

CSS 教程: Styling Forms


默认CSS设置

大多数浏览器将使用以下默认值显示 <form> 元素:

实例

form {
  display: block;
  margin-top: 0em;
} 
亲自试一试 »

Copyright ©2020-2026 freew3c.com All Rights Reserved 提供的内容仅用于学习和测试,不保证内容的正确性。