From July 29 to August 8, I read the book on and off, and made some practice connections. The overall feeling of this book really can only be a primer, after learning to see the library of the chapter is a big pit, the practice of most should be used in a ready-made library bar, so also to re-learn a library, but this book is to the language including the study of the DOM has laid a foundation, understand the underlying things, To make the library a better place to use it. Overall, the difficulty entry level, the reading experience is good. Note: Read the book Must yourself Knock code, there will be a lot of unexpected mistakes, you learn to debug to find errors and correct, this is an essential ability.
A brief history of JavaScript
The JavaScript language makes Web pages interactive. is a scripting language that needs to be interpreted and executed by the browser and cannot be run independently as a program in normal sense.
The DOM is a set of methods for abstracting and conceptualizing the contents of a document. is an Application interface API (a set of basic conventions that are mutually agreed upon by the parties concerned). Definition: An interface that is independent of the system platform and programming language through which programs and scripts can dynamically access and modify the content, structure, and style of the document. JavaScript is just one of the languages in which the DOM is used.
Second, JavaScript syntax
1. Writing JavaScript scripts requires only a text editor and a Web browser.
Insert the JavaScript script in the HTML document:
(1) Insert code directly in the head of HTML <script>......</script>
(2) Save the code as a standalone. js file, referencing <script src= "" In the head "></script>
(3) It is best to put the JS file before the </body> tag reference. This allows the browser to load the page more quickly.
2, the programming language is divided into the compilation type and the explanation type.
Compiler: such as Java C needs a compiler compiler, compiler is a program that can be written in Java and other languages to translate the source code directly on the computer to execute files. Code written in a compiled language has errors that can be discovered during the compilation phase. Compiled languages tend to be faster and more portable.
Explanatory: Interpreted languages do not require compilers, only interpreters. The JavaScript browser is able to complete the interpretation and execution of the work.
3. JavaScript syntax
Statement statement: Ends with a semicolon at the end of each statement.
Note Comment: Single-line pre-use "//", Multiline with/*......*/
Variable variable: It is best to declare in advance that variable names cannot contain spaces and punctuation marks, and are generally named with an underscore or camel case.
Data type: JavaScript is a weakly typed weakly typed language that does not declare a type when declaring a variable, and can change the data type of the variable at any stage.
String: must be enclosed in quotation marks, both single and double quotes. Inside and outside the double, inside the double outside single.
Array Array:var beatles=array (); Padding array: var beatles=array ("John", "Paul"); or var beatles=["John", "Paul"); array elements can be mixed in different types, either as variables or as arrays. Use subscript to get element beatles[0]= "John"
Object Object:var lennon=object (); Gets the element using the. Dot number. Padding object: Var lennon=object (); Lennon.name= "John";
lennon.year=1940, or var lennon={name: "John", year:1940};
4. Operation Operation
Arithmetic operators: = +-*/, where + can also be used as a splicing character concatenation, the two strings together, you can also join strings and numbers together, the numbers are automatically converted to strings.
5. Conditional statement Conditional statement
If statement, if it is a single line of statement curly braces can not. If the statement inside the IF () is true, the statement in the curly braces executes.
if (condition) {
statements;
}
Among them, the comparison operator = =, there is a strong comparison = = =, not only the comparison value will also compare the type.
6. Circular statements
While loop:
while (condition) {
statements;
As long as the condition is true, the code in the curly braces is executed repeatedly.
do{
statements;
}while (condition);
The inner code of the loop statement is executed at least once.
For loop:
for (initial condition; test condition; increment condition) {
statements;
}
7. Function functions
Function name (ARGUMENT1,ARGUMENT2) {
statements;
} function naming is usually used in hump method.
Variables are classified according to scope scope, global variable and local variables, local variable, which are generally used inside functions, except for other functions where the function is not available elsewhere. When declaring Var total= is a local variable, no var only total= is a global variable.
8. Object
Objects are data entities that are grouped together by property properties and Method methods. JavaScript has many built-in objects and host objects.
Third, DOM
Dom:document Document Object objects (divided into user-defined objects, built-in objects, host objects) model models (DOM represents a document as a family tree)
1 node
A document is a collection of nodes, with many different types of nodes.
Elements node element, text node (always contained within element node), attribute node Attibute node (not necessarily per element node)
2. Get elements
Gets the element through the element ID name. document.getElementById ("Purchase")
Gets a set of elements through the tag name tagname. document.getElementsByTagName ("a")
Gets a set of elements through the class name ClassName, but is supported only by newer browsers. Document.getelementsbyclassname ("Important Sale") Multiple class names are separated by spaces
3. Get and Set properties
Object.getattribute ("title"); Gets the title property of the object
Object.setattribute ("title", "a list of goods"); Sets the title property to a list of goods for object objects
Note: The properties that are set by setattribute are found and the modifications do not appear in the source code of the document itself. Because DOM works by loading the static content of the document and then dynamically refreshing it, while dynamic refresh does not affect the static content of the document.
"Dry" JavaScript DOM programming Art Learning Note 1-3