Document Object Content Collection (compare full) _ Basics

Source: Internet
Author: User
Document text Object-JavaScript scripting language description
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 is not an object \\\\\"

Object Properties
Document.title//Set document title equivalent to HTML title tag
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
Common 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
Document.body.appendChild (Otag)

body-the principal child object
Document.body//Specifies that the start and end of the document body is equivalent to body>/body>
Document.body.bgColor//Sets or gets the background color behind the object link color
Document.body.alink//Activate the color of the link (focus on this link)
Document.body.vlink//clicked on link color
Document.body.text//Text color
Document.body.innerText//Set the text between body>.../body>
Document.body.innerHTML//Set of HTML code between body>.../body>
Document.body.topMargin//page top margin
Document.body.leftMargin//Page left margin
Document.body.rightMargin//Page right margin
Document.body.bottomMargin//Page Bottom margin
Document.body.background//Background picture

Document.body.appendChild (Otag)//dynamically generate an HTML object

Common Object Events
Document.body.onclick= "func ()"//mouse pointer Click object is triggered
Document.body.onmouseover= when the "func ()"//mouse pointer moves over an object
Trigger when document.body.onmouseout= "func ()"//mouse pointer moves out of an object
location-Position child Object

Document.location.hash//#号后的部分 name + port number
Document.location.href//Full URL
Document.location.pathname//directory section
Document.location.port//Port number
Document.location.protocol//Network Protocol (http:) of parts after

Documeny.location.reload ()//Refresh Page
Document.location.reload (URL)//Open new page
Document.location.assign (URL)//Open new page
Document.location.replace (URL)//Open new page
selection-Selection Child Objects

Images collection (image on page)

A) by reference to the collection
Document.images//the IMG tag on the corresponding page
Document.images.length//The number of IMG tags on the page
Document.images[0]//1th img Tag
Document.images[i]//i-1 img Tags

b) Direct reference through the Nane property
IMG name= "Oimage"
Document.images.oImage// Properties

c) referencing the SRC attribute of a picture
Document.images.oImage.src// properties. src

d) Create an image
var oimage
Oimage = new Image ()
Document.images.oimage.src= "1.jpg"
Also create an IMG/tag on the page to show


Forms collection (Forms on page)

A) by reference to the collection
Document.forms//corresponding form labels on the page
Number of/formform labels on the document.forms.length//corresponding page
Document.forms[0]//1th/formform label
Document.forms[i]//i-1/formform label
Number of controls in Document.forms[i].length//I-1/formform
DOCUMENT.FORMS[I].ELEMENTS[J]//i-1 j-1 controls in/formform

b) direct reference through the label Name property
/formform name= "Myform" >input name= "Myctrl"/>/form
Document. Myform.myctrl//document. Table Single-name. Control Name

c) Accessing the properties of the form
Document.forms[i].name//Corresponding Form Name> property
Document.forms[i].action//Correspondence/formform action> Properties
Document.forms[i].encoding//Correspondence/formform enctype> Properties
Document.forms[i].target//Correspondence/formform target> Properties

Document.forms[i].appendchild (Otag)//Insert a control dynamically
DOCUMENT.ALL.ODIV//reference layer Odiv ""//Layer set to Visual "None"//layer set to hidden
Document.getelementid ("Odiv")//Reference object by Getelementid
Document.getelementid ("Odiv"). style= ""
Document.getelementid ("Odiv"). display= "None"
/*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.

4 properties of a Layer object
document.getElementById ("ID"). innertext//Dynamic output text
document.getElementById ("ID"). InnerHTML//Dynamic output HTML
document.getElementById ("ID"). Outertext//InnerText
document.getElementById ("ID"). outerHTML//innerHTML

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: 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.