JavaScript is a kind of lightweight programming language, Web page of various interactive behavior, by JS implementation;
There are three ways to introduce JS:
A write directly inside the HTML tag
b written in the HTML file, written in <script>.........</script>, can be anywhere in the HTML file
C External JS file, like an external CSS file, the introduction of the syntax is <script src= "file name. js" type= "Text/javascript" ></script>
When a nesting occurs, you need to separate the double and single quotation marks;
JS three kinds of pop-up windows
Warning pop-up: Alert ("")
Confirmation dialog: Confirm pops up a dialog box to choose, click OK to return True, click Cancel to return to Flase
User-Selectable dialog box for content: Prompt
There are two ways to JS annotations:
Annotate a single line of content
/* * * Comment out multiple lines of content
JS Display the Data method:
document.write (""): content is displayed directly in the HTML
Console.log (): Browser's debug console
JS Syntax:
String with "" or "," means literally.
JS variables need to be defined as Var:
var a
A = 1, 2, 3 、、、 if the string is quoted
Operator:
Mathematical operators: +-*/% (take remainder) + + (plus 1)-(minus 1);
Relational operators: = = =! > >= < <=;
Logical operator:&& | | !;
Note: = is the meaning of the assignment
Conditional statement: If ELSE syntax
if (condition) {
If the condition is true, execute the code
}else{
Otherwise, execute the code here
}
You can add the else if setting multiple conditional statements;
Conditional statement, you can set nested, if (condition) {
if (condition) {
}else{
}
}
Switch statement: Syntax:
Switch(n variable ) {
Case 1:
Executing code block 1
break; (without break, you will always look down and execute the code with break)
< Span class= "hl-reserved" > Case 2:
< Span class= "hl-reserved" > Execute code block 2
< Span class= "hl-reserved" > br Eak
< Span class= "hl-reserved" > default: with case 1case 2 code }
< Span class= "Hl-code" > < Span class= "hl-reserved" > f or loop: syntax
< Span class= "hl-reserved" > < Span class= "Hl-code" >for (initial value (var a =1) , cyclic condition (a<=10), change condition (a++)) {
< Span class= "Hl-code" > < Span class= "hl-reserved" > Write in the inner face to loop together
< Span class= "Hl-code" > < Span class= "hl-reserved" > }< /span> < Span class= "Hl-code" > < Span class= "hl-reserved" > outside Face only once
< Span class= "hl-reserved" > < Span class= "Hl-code" > You can add a for inside for: The loop is out, the loop is complete
for (initial value (Var a =1), loop condition (a<=10), change condition (a++)) {
for (var x =1; x<= 2; X + +) {
}
When the external for loop is once, wait for the inside for two times to complete the loop, the parent for the next time;
JavaScript Preliminary Summary