php 按钮的属性值,HTML <button> 标签 formmethod属性

本文详细介绍了HTML表单中的formmethod属性,该属性决定了表单数据如何被发送(GET或POST)。文章对比了这两种方法的特点,包括安全性、数据长度限制、缓存能力等。

HTML 标签 formmethod属性

1a95e22c8824affa31c56e50c71da07e.pngformmethod属性指以何种形式发送数据。formmethod属性会覆盖

元素的method 属性。

案例

当点击第一个按钮时表单会以method属性值提交,第二个按钮则以formmethod值覆盖method属性后提交

668c12005c6f3f51d791c797fa8679f4.png

姓氏:

名字: 

get方式

post方式

支持浏览器

Internet Explorer 9 及之前的版本不支持 标签的 formmethod 属性

95ffd7c42d970fdbc512701bb4a26945.png

3a729b84d94519de1c82c0b6fa62e04e.png

9b32a8cec84269d33d84cad24320dd13.png

1b0c219e477a6675726a96c9791fec2c.png

12496100f50e4260f8154a3be171818f.pngformmethod属性值值描述

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

post以 HTTP post 事务的形式发送表单数据(form-data)。

语法

GET 方法

请注意,查询字符串(名称/值对)是在 GET 请求的 URL 中发送的,参数写在 ? 后面,用 & 分割:/form_method.php?xing=value1&ming=value2

POST 方法

请注意,查询字符串(名称/值对)是在 POST 请求的 HTTP 消息主体中发送的,POST则不会在URL地址上显示:POST /form_method.php HTTP/1.1

Host: xuandaima.com

xing=value1&ming=value2

GET和POST对比GETPOST

后退按钮/刷新无害数据会被重新提交(浏览器应该告知用户数据会被重新提交)。

书签可收藏为书签不可收藏为书签

缓存能被缓存不能缓存

编码类型application/x-www-form-urlencodedapplication/x-www-form-urlencoded 或 multipart/form-data。为二进制数据使用多重编码。

历史参数保留在浏览器历史中。参数不会保存在浏览器历史中。

对数据长度的限制是的。当发送数据时,GET 方法向 URL 添加数据;URL 的长度是受限制的(URL 的最大长度是 2048 个字符)。无限制。

对数据类型的限制只允许 ASCII 字符。没有限制。也允许二进制数据。

安全性与 POST 相比,GET 的安全性较差,因为所发送的数据是 URL 的一部分。

在发送密码或其他敏感信息时绝不要使用 GET !POST 比 GET 更安全,因为参数不会被保存在浏览器历史或 web 服务器日志中。

可见性数据在 URL 中对所有人都是可见的。数据不会显示在 URL 中。

HTML的formmethod属性是讲述前端的发送方式,如果你想了解后台接收方式可以查看PHP表单提交

<h1>注册信息</h1> <form action="action_page.php" method="get"> <label>姓名:</label><input type="text" placeholder="请输入真实姓名"> <br></br> <label>密码:</label><input type="password" placeholder="请输入密码"> <br></br> <label>确认密码:</label><input type="password" placeholder="请输入确认密码"> <br></br> <label>性别:</label> <label><input type="radio" name="gender"> 男</label> <label><input type="radio" name="gender" checked> 女</label> <br></br> <label>居住城市:</label> <select> <option>北京</option> <option>上海</option> <option>广州</option> <option>深圳</option> <option>武汉</option> </select> <h2>教育经历</h2> <label>最高学历:</label> <select> <option>博士</option> <option>硕士</option> <option>本科</option> <option>大专</option> </select> <br></br> <label>学校名称:</label><input type="text"> <br></br> <label>所学专业:</label><input type="text"> <br></br> <label>在校时间:</label> <select> <option>2015</option> <option>2016</option> <option>2017</option> <option>2018</option> </select> <br></br> <select> <option>2019</option> <option>2020</option> <option>2021</option> <option>2022</option> </select> <br></br> <h2>工作经历</h2> <label>公司名称:</label><input type="text"> <br></br> <label>工作描述:</label> <br> <textarea></textarea> <br></br> <input type="checkbox"><label>已阅读并同意以下协议:</label> <ul> <li><a href="#">《用户服务协议》</a></li> <li><a href="#">《隐私政策》</a></li> </ul> <br></br> <button>免费注册</button> <button type="reset">重新填写</button> </form>
04-03
<html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>www.qiandu.com</title> </head> <body> <h1>wasai</h1> <p id='123'>不错</p> <img src="1.jpg"> <audio src="1.mp3">asd</audio> <video src="2.mp4">视频</video> <table border="1"> <caption>aaa</caption> <tr> <th>序号</th> <th>姓名</th> <th>性别</th> <th>年龄</th> </tr> <tr> <td>1</td> <td>张三</td> <td>男</td> <td>18</td> </tr> <tr> <td>2</td> <td>王五</td> <td>男</td> <td>22</td> </tr> </table> <br> <a href="login.html">登陆</a> <form action="login.php" method="get" onclick="alert('')"> <script> function test() { var a=document.getElementById('username').value; var a=document.getElementById('password').value; alert("用户名:" + username + "\n密码:" + password); return false; // 阻止表单提交 } </script> 用户:<input type="text"id="username" name="username"><br> 密码:<input type="password" id="password" name="password"><br> 男:<input type="radio" name="sex" value="nan"> 女:<input type="radio" name="sex" value="nv"><br> 打游戏:<input type="checkbox" name="xq[]"> 听音乐:<input type="checkbox" name="xq[]"> 看小说:<input type="checkbox" name="xq[]"><br> <select id="2" name="city" > <option>成都</option> <option>广安</option> <option>北京</option> </select> <input type="file" name="file"> <textarea id="1" name="" rows="5" cols="4"></textarea> <input type="button" value="提交" name= "" > <button>注册</button> </form> <script src="test.js"></script> </body> </html>
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值