HTML <button> formmethod 属性
标签" href="tag-main.html"><main>
<map>
<mark>
<menu>
<meta>
<meter>
<nav>
<noframes>
<noscript>
<object>
<ol>
<optgroup>
<option>
<output>
<p>
<param>
<pre>
<html>
<picture>
<progress>
<q>
<rp>
<rt>
<ruby>
<s>
<samp>
<script>
<section>
<select>
<small>
<source>
<span>
<strike>
<strong>
<style>
<sub>
<summary>
<sup>
<table>
<tbody>
<td>
<textarea>
< template>
<tfoot>
<th>
<thead>
<time>
<title>
<tr>
<track>
<tt>
<u>
<ul>
<var>
<video>
<wbr>
HTML <button> formmethod 属性
实例
带有两个提交按钮的表单,第一个提交按钮使用 method="get" 提交表单数据,第二个提交按钮使用 method="post" 提交表单数据:
<form action="demo_form.html" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<button type="submit">提交</button>
<button type="submit" formmethod="post" formaction="demo_post.html">
使用 POST 提交</button>
</form>
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<button type="submit">提交</button>
<button type="submit" formmethod="post" formaction="demo_post.html">
使用 POST 提交</button>
</form>
浏览器支持
Internet Explorer 10, Firefox, Opera, Chrome, 和 Safari 支持 formmethod 属性。
注意:Internet Explorer 9 及更早IE版本不支持 formmethod 属性。
定义和用法
formmethod 属性制定发送表单数据使用的 HTTP 方法。formmethod 属性覆盖 form 元素的 method 属性。
formmethod 属性需与 type="submit" 配合使用。
可以通过以下方式发送 form-data :
- 以 URL 变量 (使用 method="get") 的形式来发送
- 以 HTTP post (使用 method="post") 的形式来发送
使用 "get" 方法:
- 表单数据在URL中以 name/value 对出现。
- get传送的数据量较小,不能大于2KB,这主要是因为受URL长度限制。
- 不要使用 "get" 方法传送敏感信息!(密码或者敏感信息会出现在浏览器的地址栏中)
使用 "post" 方法:
- 以 HTTP post 形式发送表单数据。
- 比 "get" 方法更强大更安全。
- 没有大小限制
HTML 4.01 与 HTML5之间的差异
formmethod 属性是 HTML 5 中的新属性。
语法
<button type="submit" formmethod="get|post">
属性值
| 值 | 描述 |
|---|---|
| get | 向 URL 追加表单数据(form-data):URL?name=value&name=value |
| post | 以 HTTP post 事务的形式发送表单数据(form-data) |
HTML <button> 标签