我們知道,在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();
})