HTML DOM Button Object

来源:互联网 发布:仿淘宝商城源码html 编辑:程序博客网 时间:2024/05/20 18:17

Button Object

The Button object represents a push button.

For each <button> tag in an HTML document, a Button object is created.

Inside an HTML button element you can put content, like text or images. This is the difference between this element and buttons created with the input element.


Button Object Properties

W3C: W3C Standard.

PropertyDescriptionW3CformReturns a reference to the form that contains a buttonYesnameSets or returns the value of the name attribute of a buttonYestypeSets or returns the type of a buttonYesvalueSets or returns the value of the value attribute of a buttonYes

Standard Properties, Methods, and Events

The Button object also supports the standard properties, methods, and events.


Button type Property

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 for Internet Explorer is "button", while in other browsers (and in the W3C specification) it is "submit".

Syntax

buttonObject.type=value

The type property can have one of the following values:

ValueDescriptionsubmitThe button is a submit button (this is default for all browsers, except Internet Explorer)buttonThe button is a clickable button (this is default for Internet Explorer)resetThe button is a reset button (clears form data)

Browser Support

The type property is supported in all major browsers.


Example

Example

Return the type of a button:

<html>
<head>
<script type="text/javascript">
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 »