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"
属性值
Value | Description |
---|---|
submit | The button is a submit button (default setting for all browsers except IE). |
button | The button is a clickable button (IE default). |
reset | The button is a reset button (clears form data). |
Technical details
Return value: | String value, representing the button type. |
---|
Browser support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |
Related pages
HTML reference manual:HTML <button> type attribute