Example
The code is as follows |
Copy Code |
<script type= "Text/javascript" > $ (document). Ready (function () { $ ("button"). Click (function () { $ ("Li"). each (function () { Alert ($ (this). Text ())
}); }); }); </script> <ul> <li>Coffee</li> <li>Milk</li> <li>Soda</li> </ul> |
can achieve output
Coffee
Milk
Soda
But we
The code is as follows |
Copy Code |
<script type= "Text/javascript" > $ (document). Ready (function () { $ ("button"). Click (function () { $ ("Li"). each (function () { Alert ($ (this). Text ()) Break ; }); }); }); </script> |
Then found that there is a JS error, when I changed back again can, so feel break; in jquery, the invalid, Baidu issued the following instructions.
To implement the function of break and continue, in jquery $.each the corresponding use of return true and return false. :
The code is as follows |
Copy Code |
$ ("div"). each (function (index, Element) { Break Which is to jump out of the entire each loop return false; }); $ ("div"). each (function (index, Element) { Continue That is, jump out of each loop and execute the next loop return true; }); |