jQuery中的each函数很方便,$.each()函数封装了十分强大的遍历功能,它可以遍历一维数组、多维数组、DOM, JSON 等等。
$(":checkbox[name='sysMonitorOption'][checked=true]").each(function() { sysMonitorList.push($(this).val()); });
We can break the $.each() loop at a particular iteration by making the callback function return false. Returning non-false is the same as a continue statement in a for loop; it will skip immediately to the next iteration.
如果我们想中途continue 或者break循环怎么办。
在jQuery的each()中
return true等于continue ;
return false等于break;
但如果一个js函数也需要在each中条件不合适的时候return false;怎么办呢。目前想到的办法就是设置一个变量在each结束后判断是否return false.
参考:
http://api.jquery.com/jQuery.each/
http://www.popo4j.com/article/a-simple-imitation-of-jQuery-each.html