The exit and continue learning record of the loop in js and jquery, jsjquery
As a commodity, I learned to record 1 + 1 = 3! Error: 2
Learning records:
In js
For (var I = 1; I <5; I ++) {if (I = 3) {break; // when break is used, 2 prompts are displayed, 1, and 2; if you use continue, it will pop up three times, namely 1, 2, 4} alert (I );}
Loop, exit the loop, use break; exit the current loop to continue the next loop, use continue
To implement break in the each () method in jquery, use return false; continue, use return true
For Loop in Jquery + JS
1. As said above
2. With each, you can see that the each explanation will be passed to the element index and content of the callback function. The index starts from 0, so add 1
$ (Document). ready (function (){
$ ("Div [id ^ = 'tab ']"). each (function (I ){
$ (This). mouseover (function (){
Alert (I + 1 );
});
});
});
How can I jump out of the each loop in jquery?
The each function is a multi-execution function that executes all matching elements once. First, if you exit the current execution, use return. Second, if you want to stop running until it is not executed, I have not found a method. We recommend that you set a range limit on the previous selector to avoid this situation.