Button type 属性

定义和用法

type 属性设置或返回按钮的类型。

提示:请始终规定按钮的 type 属性

  • Internet Explorer 的默认类型是 "button"
  • 在其他浏览器(以及 W3C 规范中)是 "submit"

实例

例子 1

返回按钮的类型:

var x = document.getElementById("myBtn").type;

亲自试一试

例子 2

将按钮的类型更改为 "submit":

document.getElementById("myBtn").type = "submit";

亲自试一试

例子 3

将按钮的类型更改为 "reset":

document.getElementById("myBtn").type = "reset";

亲自试一试

语法

返回 type 属性:

buttonObject.type

设置 type 属性:

buttonObject.type = "submit|button|reset"

属性值

Valor Descripción
submit El botón es un botón de envío (configuración predeterminada en todos los navegadores excepto IE).
button El botón es un botón que se puede hacer clic (por defecto en IE).
reset El botón es un botón de reinicio (limpia los datos del formulario).

Detalles técnicos

Valor devuelto: Valor de cadena que representa el tipo de botón.

Compatibilidad con navegadores

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Soporte Soporte Soporte Soporte Soporte

Páginas relacionadas

Manual de referencia de HTML:Atributo type del <button> de HTML