JavaScript Handouts (iii)

Source: Internet
Author: User

DOM: With JS script to dynamically modify HTML

DOM Model
---------------------------------------------------------
HTML documents have only one root node, others are child nodes, and eventually form a structured document. The DOM provides a way to access structured documents, but DOM is not a technique, it's just a thought of accessing structured documents. Based on this idea, each language has its own DOM parser.

DOM Models and HTML documents
---------------------------------------------------------
Although JS is not a purely object-oriented language, Dom has found a complete set of inheritance systems for common HTML elements.
A common inclusion relationship between HTML elements. Some HTML elements can be nested between each other, and some are not.

Accessing HTML elements
---------------------------------------------------------
Two ways: Access HTML elements (document.getElementById ()) based on ID, access HTML elements using node relationships (access using parent-child, sibling relationships)

Accessing form controls
Options for accessing the list box, drop-down menu

modifying HTML elements
---------------------------------------------------------
Modify the node (content, properties, CSS styles). Modifying HTML elements is usually done by modifying several of the following common properties:
InnerHTML: such as Xx.innerhtml=document.getelementbyid ("Celval"). Value;
Value
ClassName:
Style
Options[index]:

Adding HTML elements
---------------------------------------------------------
Two-step: 1) Create/copy node; 2) Add node
var a=document.createelement ("Divxxx");
var Ajax=ul.firstchild.nextsibling.clonenode (false)
Ul.insertbefore (Ajax,ul.firstchild);

Add Table content Dynamically

Delete HTML elements
---------------------------------------------------------
Delete node: removechild

Traditional DHTML Model
---------------------------------------------------------
The DOM not only accesses and updates the content and structure of the page, but also manipulates the style of the document. JS uses the traditional DHTML model to access and update HTML pages before the DOM appears. More powerful than Dhtml,dom, it provides an access model for the entire HTML document, which transforms the document into a tree structure, with each node in the trees corresponding to the HTML element.

Using the Window object
---------------------------------------------------------
The Window object is the top-level object that the entire JS script runs.
Access history: Historical properties.
Access page URL:
Client Screens Information: Screen properties
Popup new window: window.open ()
With timer:
Navigator and location: for example
for (Var propname in Window.navigator)
{
Window.navigator[propname];
}
HTML5 New Geolocation properties: getcurrentposition,watchcurrentposition

Using the Document Object
---------------------------------------------------------
The Document object is both an instance of the HTMLDocument class and an object in the DHTML model.

JavaScript Handouts (iii)

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.