Input Submit formMethod 属性

定义和用法

formMethod 属性设置或返回提交按钮的 formmethod 属性的值。

HTML formmethod 属性定义了将表单数据发送到操作 URL 的 HTTP 方法。

formmethod 属性覆盖 <form> 元素的 method 属性.

formmethod 属性仅用于 type="submit" 的按钮。

表单数据可以作为 URL 变量 (method="get") 或作为 HTTP post 事务 (method="post") 发送。

关于 "get" 方法的注意事项:

  • 它将表单数据以名称/值对的形式附加到 URL
  • 这对于用户想要为结果添加书签的表单提交很有用
  • 您可以在 URL 中放置的数据量是有限制的(因浏览器而异),因此,您不能确定所有表单数据都会正确传输
  • 切勿使用 "get" 方法传递敏感信息! (密码或其他敏感信息将显示在浏览器的地址栏中)

关于 "post" 方法的注意事项:

  • 它将表单数据作为 HTTP post 事务发送
  • 使用 "post" 方法提交的表单无法添加书签
  • 它比 "get" 更健壮和安全
  • 它没有容量限制

注释:formmethod 属性是 HTML5 中 type="submit" 的 <input> 元素的新属性。

另请参阅:

HTML 参考手册:HTML <input> formmethod attribute

实例

例子 1

查明用于将表单提交到服务器的 HTTP 方法:

var x = document.getElementById("mySubmit").formMethod;

亲自试一试

例子 2

更改发送表单数据的方法:

document.getElementById("mySubmit").formMethod = "post";

亲自试一试

语法

返回 formMethod 属性:

submitObject.formMethod

设置 formMethod 属性:

submitObject.formMethod = get|post

属性值

描述
get 默认。将表单数据以名称/值对的形式附加到 URL: URL?name=value&name=value。
post Send form data as an HTTP post transaction.

Technical details

Return value: String value, indicating the HTTP method used to submit the form to the server.

Browser support

The numbers in the table indicate the first browser version to fully support this attribute.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 10.0 Support Support Support