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"
属性值
Valore | Descrizione |
---|---|
submit | Il pulsante è un pulsante di submit (impostazione predefinita in tutti i browser tranne IE). |
button | Il pulsante è un pulsante cliccabile (predefinito in IE). |
reset | Il pulsante è un pulsante di reset (cancella i dati del modulo). |
Dettagli tecnici
Valore di ritorno: | Valore di stringa che rappresenta il tipo di pulsante. |
---|
Supporto browser
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Supporto | Supporto | Supporto | Supporto | Supporto |
Pagine correlate
Manuale di riferimento HTML:Proprietà type dell'elemento <button> HTML