"Dry" JS related knowledge points Summary

Source: Internet
Author: User

first, get the element method

You can use the getElementById method on the built-in object document to get the element that has the id attribute set on the page, get an HTML object, and assign it to a variable. As follows:

The above statement, if the JavaScript is written on the element above, will be wrong, because the page is loaded from top to bottom, JavaScript to get the element div1 on the page, the element Div1 has not been loaded, there are two ways to solve

second, the Operation element property1, get the elements of the page, you can manipulate the properties of the page element, the operation of the property includes the reading and writing of the property.methods for manipulating properties: A, "." Action B, "[]" Action

The properties are written as follows:

A, HTML properties and JS inside the same way of writing the attributes

B, class attribute written as "ClassName"

C, the "style" attribute inside the property, there is a horizontal bar written in the camel style. For example: "Font-size" changed to "Style.fontsize"

Example: Through the "." Action Properties

B, class attribute written as "ClassName"

C, the "style" attribute inside the property, there is a horizontal bar written in the camel style. For example: "Font-size" changed to "Style.fontsize"

Example: Using the "[]" Action property

InnerHTML can read or write the contents of the label package

Third, JS function

A function is a piece of code that executes repeatedly

1. function definition and execution

2. Pre-parsing of variables and functions

The JavaScript parsing process is divided into two phases, first in the compilation phase, then in the execution phase, in advance of function-defined functions in the compile phase, and the variable declaration defined by Var is advanced, assigning it to undefined.

3. Extraction of inter-row events

The events that are called in the HTML row can be extracted into JavaScript to invoke, thus separating the structure from the behavior.

4. Anonymous function

The defined function does not give the name, which is called an anonymous function, which allows anonymous functions to be directly assigned to an element-bound event to complete the invocation of an anonymous function.

5. Function Transfer Parameter

6. function ' return ' keyword

The function of the ' return ' keyword:

A, returns the result of the function execution

B. Run of the End function

C, block default behavior

To be continued ...

"Dry" JS related knowledge points Summary

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.