Introduction to Dom and introduction to Wu Zetian
On a webpage, objects that comprise pages (or documents) are organized in a tree structure.
The top level of the page is included in the Javascript treats every item in the document tree as an object, which can be manipulated using javascript. The standard Model used to represent objects in a Document is called DOM (Document Object Model ).
Document Object set
Integration |
Description |
All [] |
Provides access to all HTML elements in the document. |
Anchors [] |
Returns a reference to all Anchor objects in the document. |
Applets |
Returns a reference to all the Applet objects in the document. |
Forms [] |
Returns reference to all Form objects in the document. |
Images [] |
Returns a reference to all Image objects in the document. |
Links [] |
Returns reference to all Area and Link objects in the document. |
var doc = document.forms; document.write(doc.length);
Obtain the array of All form forms on the page and write the length of the form array on the page, which is 2
Document Object Attributes
Genus |
Description |
Body |
Provides direct access to the <body> element. For documents that define a framework set, this attribute references the <frameset> of the outermost layer. |
Cookie |
Sets or returns all cookies related to the current document. |
Domain |
Returns the Domain Name of the current document. |
LastModified |
Returns the date and time when the document was last modified. |
Referrer |
Returns the URL of the document that loads the current document. |
Title |
Returns the title of the current document. |
URL |
Returns the URL of the current document. |
var expireDate = new Date(); expireDate.setMonth(expireDate.getMonth()+6); var userName = document.getElementById("nameField").value; document.cookie = "userName=" + userName + ";expires=" + expireDate.toGMTString();
Set browser cookies
Document Object Method
Method |
Description |
Close () |
Close the output stream opened using document. open () and display the selected data. |
GetElementById () |
Returns a reference to the first object with the specified id. |
GetElementsByName () |
Returns a set of objects with the specified name. |
GetElementsByTagName () |
Returns an object set with the specified tag name. |
Open () |
Open a stream to collect output from any document. write () or document. writeln () method. |
Write () |
Write HTML expressions or JavaScript code to the document. |
Writeln () |
It is equivalent to the write () method. The difference is that a line break is written after each expression. |
document.getElementById("days")
Obtain the HTML object with the id of days.
Note: In the preceding methods, getElementById, getElementsByName, and getElementsByTagName are commonly used to access page elements.
GetElementById returns a single object. getElementsByName indicates the set of elements obtained based on name. getElementsByTagName indicates the set of elements obtained based on tag name.