English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Manual de referencia HTML

Completo de etiquetas HTML

HTML: <button> formmethod 属性

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

 HTML <button> etiqueta

在线示例

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

!DOCTYPE html>
<html>
<head>
<title>HTML:<button> formmethod 属性 - 基础教程网 oldtoolbag.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, y Safari 支持 formmethod 属性。

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

定义和用法

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

  1. 它将表单数据以 名称/Añadir valores en forma de pares clave a la URL

  2. Muy útil para envíos de formulario donde el usuario desea agregar los resultados como favorito

  3. La cantidad de datos que se pueden放置 en la URL es limitada(puede variar entre navegadores),por lo que no se puede garantizar que todos los datos del formulario se transmitan correctamente

  4. ¡No use el método "get" para transmitir información sensible!(Las contraseñas u otra información sensible se mostrarán en la barra de direcciones del navegador)

Notas sobre el método "post":

  1. Envía los datos del formulario como transacción HTTP posterior

  2. No se puede agregar como favorito el envío de formulario con el método "post"

  3. Es más robusto y seguro que "get"

  4. No tiene límite de tamaño 

HTML 4.01 con HTML5diferencias

El atributo formmethod es HTML 5 del nuevo atributo.

Sintaxis

        <button type="submit" formmethod="get|post">

Valor del atributo

ValorDescripción
getAñadir datos del formulario a la URL(form-data):URL?name=value&name=value
postEnviar datos del formulario en forma de transacción HTTP post(form-data)
 HTML <button> etiqueta