HTML5 Mobile Development Road (--javascript) Review 4

Source: Internet
Author: User

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;"/>

  1. <html>

  2. <head>

  3. <script>

  4. var i = 100;

  5. Function F1 () {

  6. alert (i);

  7. var i = 1000;

  8. }

  9. function F2 () {

  10. var i = 1000;

  11. alert (i);

  12. }

  13. Function F3 () {

  14. alert (i);

  15. i = 1000;

  16. }

  17. function F4 () {

  18. alert (i);

  19. i = 1000;

  20. function f5 () {

  21. var i = 10000;

  22. }

  23. }

  24. F1 (); The result is undefined.

  25. F2 (); The result is 1000.

  26. F3 (); The result is 100.

  27. </Script>

  28. </head>

  29. <body>

  30. </Body>

  31. <!--

  32. Pre-compilation--scanning of scripts

  33. JS Engine--Create a Global activity object (I and F1)--Create a local active object (i) s

  34. -->

  35. </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;"/>

  1. <html>

  2. <head>

  3. <script>

  4. Function F1 () {

  5. var a1 = math.random ();

  6. alert (A1);

  7. var a2 = 100.68;

  8. Alert (Math.ceil (A2));

  9. Alert (Math.floor (A2));

  10. }

  11. function F2 () {

  12. Math.floor (Math.random () *33);

  13. }

  14. F1 ();

  15. </Script>

  16. </head>

  17. <body>

  18. </Body>

  19. <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

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.