JavaScript scripting language Description: Document text block object detailed

Source: Internet
Author: User
Javascript| Object | script | detailed

---------------------------------------------------------------------
Note: The names of the element name attribute and JavaScript reference on the page must be consistent including case
Or you'll be prompted with an error message "The referenced element is empty or not an object"
---------------------------------------------------------------------

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

Images collection (image on 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

b) Direct reference through the Nane property

Document.images.oImage//document.images.name Properties

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= "Http://www.webjx.com/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= "Http://www.webjx.com/1.jpg"
</script>

----------------------------------------------------------------------

Forms collection (Forms on page)

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 text Password box value
document.write (document. Myform.oText.value)
document.write (document. Myform.oPswd.value)
</script>
--------------------------------------------------- --------------------
<!--Select control related script-->
<form name= "Myform"
< Select Name= "Oselect"
<option value= "1" >1</OPTION>
<option value= "2" >2</option>
<option value= "3" >3</option>
</select>
</form>

<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 the selected option
  //(based on 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.



Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.