Document Object-Javascript script language description
---------------------------------------------------------------------
Note: The element name attribute on the page and the name referenced by JavaScript must be case-sensitive.
Otherwise, you will be prompted with an error message "the referenced element is null or not an object"
---------------------------------------------------------------------
Object Attributes
Document. Title // set the document title is equivalent to the <title> tag of HTML.
Document. bgcolor // set the background color of the page
Document. fgcolor // set the foreground color (text color)
Document. linkcolor // The link color that has not been clicked
Document. alinkcolor // the color of the activation Link (focus on this link)
Document. vlinkcolor // the color of the clicked Link
Document. url // set the URL attribute to open another webpage in the same window
Document. filecreateddate // file creation date, read-only attribute
Document. filemodifieddate // file modification date, read-only attribute
Document. filesize // file size, read-only attribute
Document. Cookie // set and read cookies
Document. charset // set the character set to simplified Chinese: gb2312
---------------------------------------------------------------------
Object Method
Document. Write () // dynamically write content to the page
Document. createelement (TAG) // create an HTML Tag object
Document. getelementbyid (ID) // get the object with the specified id value
Document. getelementsbyname (name) // get the object with the specified name value
---------------------------------------------------------------------
Images set (images in the page)
A) reference through a set
Document. Images // The label on the corresponding page
Document. Images. Length // Number of labels on the corresponding page
Document. Images [0] // 1st tags
Document. Images [I] // The I-1 label
B) direct reference through the Nane attribute
Document. Images. oimage // document. Images. Name attribute
C) reference the image's src attribute
Document. Images. oimage. SRC // document. Images. Name attribute. SRC
D) create an image
VaR oimage
Oimage = new image ()
Document. Images. oimage. src = "/1.jpg"
At the same time, you can create a tag on the page to display it.
<HTML>
<Script language = "JavaScript">
VaR oimage
Oimage = new image ()
Document. Images. oimage. src = "/1.jpg"
</SCRIPT>
</Html>
----------------------------------------------------------------------
Forms set (forms in the page)
A) reference through a set
Document. Forms // The <form> tag on the corresponding page
Document. Forms. Length // Number of <form> labels on the corresponding page
Document. Forms [0] // 1st <form> tags
Document. Forms [I] // The I-1 <form> label
Document. Forms [I]. Length // number of controls in the I-1 <form>
Document. Forms [I]. elements [J] // The I-1 control in the J-1 <form>
B) direct reference through the label name attribute
<Form name = "myform"> <input name = "myctrl"> </form>
Document. myform. myctrl // document. form name. Control name
-----------------------------------------------------------------------
---------------------------------------------------------------
1 2 3
<Script language = "JavaScript">
// Traverse the option items of the Select Control
VaR Length
Length = Document. myform. oselect. Length
For (I = 0; I <length; I ++)
Document. Write (document. myform. oselect [I]. value)
</SCRIPT>
<Script language = "JavaScript">
// Traverse the option and determine whether an option is selected
For (I = 0; I <document. myform. oselect. length; I ++ ){
If (document. myform. oselect [I]. Selected! = True)
Document. Write (document. myform. oselect [I]. value)
Else
Document. Write ("<font color = Red>" + document. myform. oselect [I]. Value + "</font> ")
}
</SCRIPT>
<Script language = "JavaScript">
// Dynamically Add the option item of the Select Control
VaR ooption = Document. createelement ("option ");
Ooption. Text = "4 ";
Ooption. value = "4 ";
Document. myform. oselect. Add (ooption );
</SCRIPT>
<HTML>
-----------------------------------------------------------------------
<Div id = "odiv"> text </div>
Document. All. odiv // reference layer odiv
Document. All. odiv. Style
Document. All. odiv. style. Display = "" // set the layer to visible.
Document. All. odiv. style. Display = "NONE" // The layers are hidden.
/* Document. All indicates the set of all objects in the document.
Only ie supports this attribute, so it is also used to determine the browser type */