javascript-1 basic grammar

javaScript
1, what is it?
2, what does it do?
3, how to use it?

 

1 What is?

JavaScript is a scripting language : exist in text form, it only when you call to explain the implementation. (Compile java is different from the run after)

In 1995, by Netscape's Brendan Eich, on the Netscape Navigator browser for the first time from design and implementation. Its management hierarchy wanted it to look to look like Java, so named for JavaScript.

composition:

  ECMAScript: Syntax (ECMA (European Computer Manufacturers Association) to develop a unified)
  the DOM: the Document Object Model (Document Object Model: core object the Document)
  BOM: Browser Object Model (browser object model: core object window)

2, the role?
1) to reduce the pressure on the server (such as form validation can be performed)
2) as a Web page to add some dynamic effects (such as skin, image carousel)

3, how to use it?
  1. tools: text editor can, html what tools, javascript you can use what tools 
  2. Where to write code

    Js code introduced using a script tag, this tag can be written at any location in the document, generally written in the <head> </ head> tags

    1) js code written directly in the script tag:

    <script type="text/javascript">

      // javascript codes

    </script>

    2) the introduction of external javascript files: <script type = "text / javascript" src = "file path"> </ script>

    The introduction myJS.js js file in the folder: <script type = "text / javascript" src = "js / myJs.js"> </ script>


  3. The basic syntax:
    JavaScript syntax:
      1. Variables   

          Declare variables (without the specific data type): 

            While assignment statement: var variable name = value; // such as: var a = 10086;     

            After the first assignment statement: var variable name; variable name = value; // such as: var b; b = 10011;

          5 kinds of primitive data types: boolean boolean value number string string undefined (value not given) null (typeof acquired variable name data type of the variable)

          Html page output to the sentence: document.write (); such as: document.write ( "nice weather");

          Pop-up box: alert (); such as: alert ( "Congratulations, poisoned!");

      2. Operator: with java
      3. Control statements: with java
      Note 4

        // single-line           multi-line / * * /

      The type conversion
        the parseInt ( "string")
        parseFloat ( "string")

 

4, case

<Script type = "text / JavaScript"> 
   // simple sentence output 
    document.write ( "first line, hot heat"); 
    // output flag 
    document.write ( "<p> God, cold, too difficult ~ </ p> "); 
    tag tape // output attributes: double quotation marks into a single attribute value 
    document.write (" <font color = ' red' size = '6'> nice weather < / font> "); 

    var. 1 = a; // declare variables var variable name = value; var variable name; variable name = value; 
    var b = 3.14; 
    var C =" flower "; 
    the value of variable b // print output , the variable require double quotes 
    document.write (b); 
    // pop up a message box typeof acquired variable name data type of the variable 
    alert ( "type b is:" + typeof b); 
</ Script>

  

      

Guess you like

Origin www.cnblogs.com/1810-zx/p/11369704.html