1.if (condition) { //condition set up walk code body, do not set skip;
code body;
} //When only one condition is judged, and only one code body is left, the
with this;
2.if (condition) { //condition set Go, code Body 1, not set go else
code body 2;
code body 1;
}else{
Code Body 2
} //As a condition, and there are two methods, you can use the
this;
3.if (condition 1) { //which condition is set to go which code body, otherwise walk generation
code body 5;
Code Body 1
}else if (condition 2) {
Code Body 2
}else if (condition 3) {
Code Body 3
}else if (condition 4) {
Code Body 4
}else{
Code Body 5
}
Use this when you encounter multiple conditions of judgment;
/ * NOTE * *
a way to create a switch when you encounter a condition that is not able to make a judgment
, to manually create a condition to judge;
example:
The src in img is not to be judged by the condition;
var flag =true;//Create a switch: Boolean value: True True
(1) False----(0)
if (flag) {//When flag is true, enter into the following code body; The value of flag is changed to false;
oimg.src= "Img/3.jpg";
Flag=false; //change flag to False
}else{//When flag is false, enter into the following code body; change the value of Flage to true;
oimg.src = "img/1.jpg";
}
Three. The array in JS
Array: Equivalent to a warehouse, can store various values.
Cases:
var arr = [1,2,3,4,5,6] //stored here is a number type, when
You can also have other types (such as: strings, numbers, tags ...),
are separated by the "," number.
The array is starting from 0, which is the subscript starting from 0;
Example: Finding an array:
ARR[0]//Find the first number, enter 1 to find a second number
, and then click Down.
There are many ways to manipulate the data inside the array.
1.arr.length: Get the length of the data; (generally find the last one, straight
Use length-1, which means the last number)
Example: arr.length-1; Get the last number.
2.arr.push (); Add data to the array;
Example: Arr.push (7); Add a 7 to the array;
Four. Js-for Application
1> the second method of getting an element:
document.getElementById (' ID name ');//Find a label ... (
static method);
document.getElementsByTagName (' tag name ');//Find page
All labels in the polygon; (Dynamic method)
Note: You must add "[]" when using tagname, because the returned
is a collection, something similar to an array;
document.getelementbyid and
1.getelementbyid can only be preceded by document;
getelementsbytagname front can be either with document, or
can be followed by other variables;
2.getelementbyid only find an element, and
3.getelementbyid is static; if there is no ID on the page, find the
----loop----
for (var i=0;i<10;i++) {
loop body
}
Span style= "FONT-SIZE:18PX; Color: #ff0000; " > Loop step:
First step: Assign the variable i to 0; (of course, the assignment is a few can, specifically
Second step: Determine whether i<10; is true, I is less than ten;
step three: After judging to be true, go to the code inside the loop body below;
Fourth step: Walk through the code of the loop body, walk i++; The value of the previous I from
Plus (that is, add 1);
Fifth step: To determine whether I<10 is true after the addition of I; for
> really continue to walk 1--4, class heap, and when the i<10 is False (also
----loop----of circulating sleeves
for (var i =0;i<10;i++) {
for (Var j =0; J <10;j++) {
Loop body
}
}
Loop method:
The outermost loop is judged as true after walking inside the loop;
Inside the cycle of all the cycle of judgment, go, and then go back outside to continue to sentence
A broken cycle, in turn, a class heap;
The total said is: Outside the loop to walk once, inside the cycle is finished;
JS Basis--Condition judgment