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 | Tombol adalah tombol submit (default semua pelayar kecuali IE). |
button | Tombol adalah tombol yang boleh di klik (default IE). |
reset | Tombol adalah tombol reset (menghapus data formulir). |
Perincian teknikal
Hasil balik: | Nilai string, menunjukkan jenis tombol. |
---|
Dukungan pelayar
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Dukungan | Dukungan | Dukungan | Dukungan | Dukungan |
Laman berkaitan
Panduan HTML:Sifat type <button> HTML