Dom, JavaScript

Source: Internet
Author: User

 

1. Javascript

Basic concepts:Javascript is a client scripting language that is based on objects and events and is relatively secure. It is also a scripting language widely used in client web development. It is often used to add dynamic functions to HTML web pages, such as responding to various user operations. Javascript is an object-oriented dynamic client scripting language that is prototyped and inherited from Netscape livescript. It is mainly designed to address server-side languages, the speed issues left over to provide customers with smoother browsing results.

Dom-based relationships: Dom is short for Document Object Model. It allows JavaScript to interact with pages and dynamically modify nodes, elements, and attributes in documents. Dom is applicable not only to XHTML documents, but also to all XML documents.

Two built-in functions:

EVal function: used to calculate the value of A (string) expression.

Isnan function: used to verify whether the parameter is Nan (not a number). A boolean value is returned.

 

2. What is Dom?

Dom is the abbreviation of Document Object Model object model. It accesses and modifies the content and structure of a document in a way independent of platform and language. In other words, it is a common method to represent and process an HTML or XML document. It can be used in any programming language. Is a programming interface for HTML and XML documents. It provides a structured representation for the document, which can change the content and presentation of the document. Dom connects web pages with scripts and other programming languages. Is the relationship between a tree and a node.

The Document Object Model is also nested in layers, but is often understood as the shape of a tree. The root is a window or document object, which is equivalent to the periphery of the outermost tag, that is, the entire document.
From inner to outer root-> nodes-> node: Window à document
We use JavaScript to perform all operations on webpages Through Dom. Dom is the core content defined in the browser rather than the Javascript language specification.
 
Personal Understanding: it is part of the JavaScript Application. Dom can be used by JavaScript to read and change HTML, XHTML, and XML documents. Javascript allows you to refactor the entire HTML document. You can add, remove, change, or rearrange projects on the page.
To change something on the page, JavaScript needs to obtain an entry to access all elements in the HTML document. This entry, along with the methods and attributes for adding, moving, changing, or removing HTML elements, is obtained through the Document Object Model (DOM ).
 

Dom and JavaScript

95% of the frequently asked questions about JavaScript are actually Dom issues. People do not like Dom in their habits, either JavaScript or Ajax. We use JavaScript to perform all operations on webpages Through Dom. Dom is the core content of the browser, rather than the content specified in the Javascript language specification. If you download a reference help document for the Javascript language, it is even a well-known document. the write method cannot be found.

The following code uses a prompt box to show the URLs of all links on the webpage one by one. The red part of the code is Dom.
VaR anchortags = Document. getelementsbytagname ("");
For (VAR I = 0; I <anchortags. length; I ++)
{
Alert ("href of this a element is:" + anchortags [I]. href + "/N ");
}

In this way, the core JavaScript and Dom can be clearly understood.

VaR anchortags =
A JavaScript variable named anchortags is created.

Document. getelementsbytagname ("")
The document interface is the first interface defined in the dom1 Core Specification, while the document interface is a host object that implements the document interface. Document controls everything on the web page.
At the core of dom1, the document interface defines the getelementsbytagname () method. This method returns a node list (nodelist), which is a dom-specific array containing nodes and contains all tags that meet the matching parameter conditions, in the order of appearance in the document. The anchortags variable is now a node list.

;
A semicolon is the end symbol of a statement in JavaScript.

For (VAR I = 0; I <
This is a typical "for loop" in programming languages ". Declare the cyclic variable I to process each node in the anchortags node list one by one. This is also JavaScript.

Anchortags. Length
The dom1 core defines the Length attribute of the nodelist interface. This attribute returns an integer indicating the number of nodes in the node list. Javascript arrays also have a Length attribute.

; I ++ ){
Typical JavaScript variable addition 1 operation.

Alert (
Alert () is a DOM method. A prompt box is displayed, showing the parameters (strings) passed to this method ). This is a member of some historical programming interfaces called level 0 Dom (DOM level 0) or dom0. Dom0 is a set of programming interfaces "supported by some browsers" (in fact, there are no browsers that do not support dom0 in the market, which can be seen only in collections of some software enthusiasts ), does not belong to any dom Standard Specification.

"Href of this a element is:" +
A string literal and a string link character. JavaScript.

Anchortags [I]. href
Href is the attribute of the htmlanchorelement interface defined in the dom1 HTML specification. It returns the value of the href attribute of the Link (<A>) element.

Here we use a usage like anchortags [I], which is the same as the syntax for accessing the array entry I in JavaScript. The so-called "dom mode" of language-neutral (irrelevant to specific language) is used to access a project in a node list by using the item () defined in the nodelist interface () method: anchortags. item (1 ). href. However, most JavaScript implementations allow you to use this simple array-like syntax, which is actually used by many people.

+ "/N ");
Another string connection. Add a carriage return to the end of the string.

}
The "for loop" ends.

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.