HTML DOM Button type 屬性
定義和用法
type 屬性可設置或者返回按鈕的類型。
提示:請始終為按鈕規定type屬性。IE 瀏覽器的默認類型是"button",而在其他瀏覽器中(以及在W3C 規範中)是"submit"。
語法
buttonObject.type=value
type 屬性可以是以下值:
值 | 描述 |
---|---|
submit | button 是提交按钮(是 IE 之外的所有浏览器的默认值) |
button | button 是可点击的按钮(IE 的默认值) |
reset | button 是重置按钮(清除表单数据) |
瀏覽器支持
所有主要瀏覽器都支持type 屬性。
實例
實例
返回按鈕的類型:
<html>
<head>
<script>
function alertType()
{
alert(document.getElementById("myButton").type)
}
</script>
</head>
<body>
<button id="myButton" type="button" onclick="alertType()">Click Me!</button>
</body>
</html>
<head>
<script>
function alertType()
{
alert(document.getElementById("myButton").type)
}
</script>
</head>
<body>
<button id="myButton" type="button" onclick="alertType()">Click Me!</button>
</body>
</html>
嘗試一下»
Button對象