Js-First Class

Source: Internet
Author: User

One, JavaScript (JS) Definition:
    • JavaScript is a kind of literal translation scripting language, which is a dynamic type, a weak type and a prototype-based language.
    • JavaScript is typically used to manipulate HTML pages, respond to user actions, verify transfer data, and so on.

    • What's the relationship between jquery and JavaScript? jquery is a JS library written by JS.
Composition:ECMAScript, which describes the syntax and basic objects of the language.Document Object Model(DOM) that describes the methods and interfaces for handling Web page content.A Browser object model (BOM) that describes the methods and interfaces that interact with the browser. Second, where is the JS code written?

1 JavaScript code can be written on the page

    • Embedded JS,
    • Outside the chain JS file, using the SRC attribute to introduce
    • Tag attribute inside (not recommended);

      1. The attributes in the script tag type="text/javascript" or the language= "JavaScript", HTML5 the new rules can be nothing to add;

      2. The script tag can be placed anywhere, in different positions, in order of loading, usually before head or body ends;

Third, write the JS code need to pay attention to what

1, strict 区分大小写 ;

2, the statement characters are half-width characters, (string inside can make any character)

3. Write a semicolon ( ; ) after some complete statement;

4, the code to 缩进 , indentation to be aligned.

Four, JS debugging 1, Alert ("string");2, Console.log ();3, document.write ();//The content in parentheses is parsed in HTML; Note: When the document flow is loaded, the content will overwrite the entire document;V. variables

When we re-use an element or some data, the content may be too long or the data will change, then we need to define the variables to replace them.

Syntax: ' var ' + ' variable name '

    • Var声明
    • Variable naming rules:

You can use ' $ ', ' _ ', ' letters ', ' numbers ', [cannot start with a number], [letters are strictly case sensitive], [see the name]

1.var abc; //Declaration not to assign value
2.var obj = 123; Declare immediately assign value

A VAR can declare multiple variables, and variables do not have to be assigned immediately

1. var a,b,c,d; //Declare multiple variables at once
2. var a = 1,b = 2, c = 3,d = 4; A variable that declares multiple declarations at once and assigns values
Six, JS in the comments
    • Single//
    • MultiRow/* */
Vii. acquiring elements
  1. get element  
    • Special label  
      • doc Ument.body
      • document.head
      • document.title
    • General label  
      • document.getElementById ()   Match ID name ...
      • Ele. getElementsByTagName ()   Match label signature is ... Collection of dynamic methods          //class array multiple
      • document.getelementsbyname ()   match name is ... Collection   Dynamic methods        //class array multiple        
      • ele . Getelementsbyclassnam E ()   Match class name ... Collection   Dynamic methods           //class array multiple
      • ele. Queryselector () ; Matches the first
      • ele of a CSS selector. Queryselectorall () ; Matches all collections that match the CSS selector  
        .   and the use of []
Viii. getting and modifying element html
      • Element HTML content
        ele.innerHTMLGet element HTML
        ele.innerhtml = ' string '; Modify Element HTML

        • Routines: "To modify the HTML content of the element (InnerHTML) of the JS code, the modified element must be in the JS code before";
      • Element text content
        Standard
        ele.textContentGet element text
        ele.textcontent = ' string '; Modify element text
        Non-standard (ie low version)
        ele.innerTextGet element text
        Ele.innertext = ' string '; Modify element text

Js-First Class

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.