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