This paper is the official HTML5 training course for Brother Lian it educational institution, the main introduction: HTML5 Mobile Development Road (4)--javascript review
The scope of a variable
The execution of a JavaScript script is divided into two stages:
In the first phase, the JS engine () scans the entire JavaScript code first. When <script> is encountered, a global active object is created, and the Declaration of variables appearing in <script> and the definition of the function are saved in the active object. If a function is encountered, the corresponding local activity object is created, and the declaration of the variable inside the function and the definition of the function are saved inside the active object.
In the second stage, the JavaScript code is executed, the variables are encountered, and the active object is found in the corresponding activity object.
[HTML] view plain copy
Print? 650) this.width=650; "src=" Https://code.csdn.net/assets/CODE_ico.png "alt=" on Code View "Width=" "height=" 12 " Style= "border:0px;"/>650) this.width=650; "src=" Https://code.csdn.net/assets/ico_fork.svg "alt=" Derivation to My Code slice " Width= "height=" style= "border:0px;"/>
<html>
<head>
<script>
var i = 100;
Function F1 () {
alert (i);
var i = 1000;
}
function F2 () {
var i = 1000;
alert (i);
}
Function F3 () {
alert (i);
i = 1000;
}
function F4 () {
alert (i);
i = 1000;
function f5 () {
var i = 10000;
}
}
F1 (); The result is undefined.
F2 (); The result is 1000.
F3 (); The result is 100.
</Script>
</head>
<body>
</Body>
<!--
Pre-compilation--scanning of scripts
JS Engine--Create a Global activity object (I and F1)--Create a local active object (i) s
-->
</html>
Math (a JavaScript built-in object that can be used directly)
Math.random (): Returns the random number from 0 to 1 0<= random number <1
Math.ceil (): Rounding up
Math.floor (): Rounding Down
[HTML] view plain copy
Print? 650) this.width=650; "src=" Https://code.csdn.net/assets/CODE_ico.png "alt=" on Code View "Width=" "height=" 12 " Style= "border:0px;"/>650) this.width=650; "src=" Https://code.csdn.net/assets/ico_fork.svg "alt=" Derivation to My Code slice " Width= "height=" style= "border:0px;"/>
<html>
<head>
<script>
Function F1 () {
var a1 = math.random ();
alert (A1);
var a2 = 100.68;
Alert (Math.ceil (A2));
Alert (Math.floor (A2));
}
function F2 () {
Math.floor (Math.random () *33);
}
F1 ();
</Script>
</head>
<body>
</Body>
<html>
Third, the system of the DOM model
1. What is DOM
Document Object Model
Transforms a structured document (XML, HTML) into a tree and provides properties or methods related to the operation of the tree (including traversal, find, modify, delete, etc.)
2. The basic structure of the DOM model
Node
Document
HTMLDocument (
htmlbodyelement (<body>)
Element
HtmlElement
htmlformelement (<form>)
htmlinputelement (<input>)
Htmlselectelement (<select>)
htmloptionelement (<option>)
HTML5 Mobile Development Road (--javascript) Review 4