HTML < button > formmethod 属性

 2022-06-13    518  

HTML <button> formmethod 属性

HTML <button> 标签

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>

注意: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
  •  

原文链接:https://77isp.com/post/1205.html

=========================================

https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。