HTML Dom tutorial 19-html Dom Button Object
1: Button Object
The button object represents a button.
Each time a <button> tag appears in an HTML document, the button object is created.
2: properties of the Button Object
attribute |
description |
ie |
F |
O |
W3C |
accesskey |
set or return the shortcut key for accessing a button. |
6 |
1 |
9 |
Yes |
disabled |
set or return whether to disable the button. |
6 |
1 |
9 |
Yes |
form |
Returns a reference to a form containing buttons. |
6 |
1 |
9 |
Yes |
id |
the ID of the set or return button. |
6 |
1 |
9 |
Yes |
name |
name of the set or return button. |
6 |
1 |
9 |
Yes |
tabindex |
set or return button's tab key control order. |
6 |
1 |
9 |
Yes |
type |
the Form Type of the return button. |
6 |
1 |
9 |
Yes |
value |
set or return the text displayed on the button. |
6 |
1 |
9 |
Yes |
3: Standard attributes
Property |
Description |
IE |
F |
O |
W3C |
Classname |
Sets or returns the class attribute of an element |
5 |
1 |
9 |
Yes |
Dir |
Sets or returns the direction of Text |
5 |
1 |
9 |
Yes |
Lang |
Sets or returns the language code for an element |
5 |
1 |
9 |
Yes |
Title |
Sets or returns an element's advisory title |
5 |
1 |
9 |
Yes |
4: classname attributes
This example shows two methods to obtain the class attribute of the <body> element:
<HTML>
<Body id = "myid" class = "mystyle">
<SCRIPT type = "text/JavaScript">
X = Document. getelementsbytagname ('body') [0];
Document. Write ("body CSS class:" +
X. classname
);
Document. Write ("<br/> ");
Document. Write ("an alternate way :");
Document. Write (
Document. getelementbyid ('myid'). classname
);
</SCRIPT>
</Body>
</Html>
Output:
Body CSS class: mystyle
An alternate way: mystyle
5. Other Properties
<HTML>
<Head>
<SCRIPT type = "text/JavaScript">
Function alertid ()
{
VaR TXT = "ID:" + document. getelementbyid ("mybutton"). ID
TXT = TXT + ", type:" + document. getelementbyid ("mybutton"). Type
TXT = TXT + ", type:" + document. getelementbyid ("mybutton"). Form
Alert (txt)
Document. getelementbyid ("mybutton"). Disabled = true
}
</SCRIPT>
</Head>
<Body>
<Form>
<Button id = "mybutton" onclick = "alertid ()"> click me! </Button>
</Form>
</Body>
</Html>