The each function cannot use the break and continue keywords. The alternative method is:
Break ---- return false;
Continue -- use return ture; conditions
Analysis
Execute a function using each matching element as the context.
This means that each time the passed function is executed, the this keyword in the function points to a different DOM element (each time it is a different matching element ). In addition, each time a function is executed, a numeric value indicating the position of the element used as the execution environment in the matched element set is passed to the function as the parameter (an integer starting from scratch ). If 'false' is returned, the loop is stopped (just like using 'break' in a normal loop '). Return 'true' to jump to the next loop (just like using 'contine' in a normal loop ').
Code
The code is as follows: |
Copy code |
$ ('. INER'). each (function (I ){ If ($ (this). attr ('name') = "continue "){ Return; // implement the continue function } Else if ($ (this). attr ('name') = "break "){ Return false; // implement the break function } }) |