HTML 参考手册

HTML 标签大全

HTML: <button> formmethod 属性

本文介绍HTML button formmethod 属性的使用方法,在线实例演示如何使用HTML button formmethod 属性、浏览器的兼容性、语法定义及它的属性值详细资料等。

 HTML <button> 标签

在线示例

具有两个提交按钮的表单。第一个提交按钮使用method ="get"提交表单数据,第二个提交按钮使用method =" post"提交表单数据:

<!DOCTYPE html>
<html>
<head>
<title>HTML:<button> formmethod 属性 - 菜鸟教程 (cainiaojc.com)</title>
<body>
<form action="action_page.php" method="get">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <button type="submit">默认get方式提交</button>
  <button type="submit" formmethod="post">post方式提交</button>
</form>
</body>
</html>
测试看看 ‹/›

浏览器兼容性

IEFirefoxOperaChromeSafari

Internet Explorer 10, Firefox, Opera, Chrome, 和 Safari 支持 formmethod 属性。

注意:Internet Explorer 9 及更早IE版本不支持 formmethod 属性。

定义和用法

formmethod属性指定发送表单数据时要使用的HTTP方法。此属性覆盖表单的  method  属性。
formmethod属性仅用于类型为“ submit”的按钮。
表单数据可以作为URL变量(使用method =“ get”)或作为HTTP post(使用method =“ post”)发送。
关于“GET”方法的注意事项:

  1. 它将表单数据以 名称/值 对的形式附加到URL

  2. 对于用户希望将结果添加为书签的表单提交非常有用

  3. 您可以在URL中放置多少数据是有限制的(浏览器之间会有所不同),因此,您不能确定所有表单数据都会正确传输

  4. 切勿使用“get”方法来传递敏感信息!(密码或其他敏感信息将在浏览器的地址栏中显示)

关于“ post”方法的注释:

  1. 它将表单数据作为HTTP后事务发送

  2. 带有“ post”方法的表单提交不能添加为书签

  3. 它比“获取”更健壮和安全

  4. 它没有大小限制 

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> 标签