Button typeProperty

Button 对象参考手册Button Object

Definition and Usage

The type property sets or returns the type of a button.

Tip:Always specify the type attribute for the button. The default type in IE browsers is "button", while in other browsers (and in the W3C specification) it is "submit".

Syntax

buttonObject.type=value

The type property can have the following values:

Value Description
submit button is a submit button (the default value for all browsers except IE)
button button is a clickable button (the default value in IE)
reset button is a reset button (clears form data)


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the type property.


Example

Example

Return the type of the button:

<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>

Try it Yourself »


Button 对象参考手册Button Object Other Extensions