导航
×
   ❮   
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> method 属性


实例

使用 "get" 方法来提交表单:

<form action="/action_page.php" 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>
亲自试一试 »

下面有更多实例。


定义和用法

method 方法规定如何发送表单数据(form-data)(表单数据会被发送到在 action 属性中规定的页面中)。

表单数据可被作为 URL 变量的形式来发送(method="get")或者作为 HTTP post 事务的形式来发送(method="post")。

关于 GET 的注释:

  • 将表单数据以名称/值对的形式附加到 URL 中
  • URL 的长度是有限的(大约 3000 字符)
  • 绝不要使用 GET 来发送敏感数据!(在 URL 中是可见的)
  • 对于用户希望加入书签的表单提交很有用
  • GET 更适用于非安全数据,比如在 Google 中查询字符串

关于 POST 的注释:

  • 将表单数据附加到 HTTP 请求的 body 内(数据不显示在 URL 中)
  • 没有长度限制
  • 通过 POST 提交的表单不能加入书签

浏览器支持

属性          
method Yes Yes Yes Yes Yes

语法

<form method="get|post">

属性值

描述
get 默认。将表单数据(form-data)以名称/值对的形式附加到 URL 中: URL?name=value&name=value
post 以 HTTP post 事务的形式发送表单数据(form-data)。

更多实例

实例

使用 "post" 方法来提交表单:

<form action="/action_page.php" method="post">
  <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>
亲自试一试 »

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