带有两个提交按钮的表单。 第一个提交按钮用 method="get" 提交表单数据,第二个用 method="post" 提交表单数据:
<form action="/action_page.php" method="get"> <label for="fname">First name:</label> <input type="text" id="fname" name="fname"><br><br> <label for="lname">Last name:</label> <input type="text" id="lname" name="lname"><br><br> <button type="submit">Submit</button> <button type="submit" formmethod="post">Submit using POST</button> </form>
formmethod 属性指定发送表单数据时使用的 HTTP 方法。此属性覆盖表单的“方法”属性。
formmethod 属性仅用于具有 type="submit" 的按钮。
表单数据可以作为 URL 变量(使用 method="get")或作为 HTTP post(使用 method="post")发送。
get 方法的注意事项:
URL 中放置多少数据是有限制的(因浏览器而异),因此,您无法确定所有表单数据都会正确传输get 方法传递敏感信息! (密码或其他敏感信息将显示在浏览器的地址栏中)关于 post 方法的注意事项:
post 方式提交的表单无法添加书签get 更健壮和安全表中的数字指定了完全支持该属性的第一个浏览器版本。
| 属性 Attribute |
|
|
|
|
|
|---|---|---|---|---|---|
| formmethod | 9.0 | 10.0 | 4.0 | 5.1 | 15.0 |
<button type="submit" formmethod="get|post">
| 值 Value | 描述 Description |
|---|---|
| get | 将表单数据附加到 URL: URL?name=value\&name=value |
| post | 将表单数据作为 HTTP 发布事务发送 |