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
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
Vii. acquiring elements
- 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