A detailed explanation of the document object of JavaScript
Source: Internet
Author: User
Javascript| Object | Detailed 1, object properties
Document.title//Set document title equivalent to HTML <title> label
Document.bgcolor//Set page background color
Document.fgcolor//Set foreground colors (text color)
Document.linkcolor//not-clicked link color
Document.alinkcolor//Activate the color of the link (focus on this link)
Document.vlinkcolor//clicked on link color
Document. URL//Set URL property to open another page in the same window
Document.filecreateddate//File creation date, read-only property
Document.filemodifieddate//File modification date, read-only property
Document.filesize//File size, read-only property
Document.cookie//Set up and read out cookies
Document.charset//Set character set Simplified Chinese: gb2312
---------------------------------------------------------------------
2. Object method
document.write ()///write content dynamically to page
Document.createelement (tag)//Create an HTML tag object
document.getElementById (ID)//Get object with specified ID value
Document.getelementsbyname (name)//Get object with specified Name value
---------------------------------------------------------------------
3, Images collection (image in the page)
A) by reference to the collection
Document.images// labels on the corresponding page
Number of tags on the document.images.length//corresponding page
Document.images[0]//1th tags
Document.images[i]//First i-1 label
c) referencing the SRC attribute of a picture
Document.images.oImage.src//document.images.name properties. src
d) Create an image
var oimage
Oimage = new Image ()
Document.images.oimage.src= "1.jpg"
At the same time, create a label on the page to show the corresponding
<script language= "JavaScript" >
var oimage
Oimage = new Image ()
Document.images.oimage.src= "1.jpg"
</script>
A) by reference to the collection
Document.forms//<form> labels on the corresponding page
Number of <form> tags on the document.forms.length//corresponding page
Document.forms[0]//1th <form> tags
Document.forms[i]//First i-1 <form> label
Number of controls in Document.forms[i].length//I-1 <form>
DOCUMENT.FORMS[I].ELEMENTS[J]//i-1 <form> j-1 controls
b) direct reference through the label Name property
<form name= "Myform" ><input name= "Myctrl" ></form>
Document. Myform.myctrl//document. Table Single-name. Control Name
-----------------------------------------------------------------------
<!--text control related script-->
<form name= "Myform" >
<input type= "text" name= "Otext" >
<input type= "Password" name= "OPSWD" >
<form>
<script language= "JavaScript" >
Get the value of the text password box
document.write (document. Myform.oText.value)
document.write (document. Myform.oPswd.value)
</script>
-----------------------------------------------------------------------
<script language= "JavaScript" >
To traverse the option item of a 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" >
Traverses the option and determines 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" >
Print out selected option according to SelectedIndex
(0 to document.) MYFORM.OSELECT.LENGTH-1)
I=document. Myform.oSelect.selectedIndex
document.write (document. Myform.oselect[i].value)
</script>
<script language= "JavaScript" >
Dynamically increase the option item for a Select control
var ooption = document.createelement ("option");
ooption.text= "4";
Ooption.value= "4";
Document. Myform.oSelect.add (ooption);
</script>
-----------------------------------------------------------------------
<div id= "Odiv" >Text</Div>
DOCUMENT.ALL.ODIV//reference layer Odiv
Document.all.oDiv.style
Document.all.odiv.style.display= ""//Layer set to Visual
Document.all.odiv.style.display= "None"//layer set to hidden
/*document.all represents a collection of all objects in the document
Only IE supports this attribute, so it is also used to determine the type of browser.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service