我们知道,在for循环中,想要跳出当前层循环,用break。而要终止当前的循环语句,而继续下一次的循环,用continue。而这两个指令在$.each中并不可用。
break:
$.each(options,function (i,option) {
if ('something' == option){
return false;//$.each循环终止
}
doSomething();
})
continue
$.each(options,function (i,option) {
if ('something' == option){
return true;//当前循环终止,当前循环不执行下面doSometing()。然后继续下次循环
}
doSomething();
})