关于js中each()使用return不能终止循环

Jquery的each里面用return false代替break;return ture代替continue
$(xx).each(function() {
      if(xx){
        return false; }else {
        return ture; 
      }
   }
});


我这里借助了一个变量来辅助判断,当不满足条件时设置为 true ,在循环外判断这个变量的值,如果变量的值是 true 则证明又不合法的值,如果变量的值为 false,则证明所需要判断的值都符合要求

var f = true;
$.each($checkbox, function (i, item) {
if (Status != "11") {
alert("xx");
f = false;
return false;
}
if (code != "") {
alert("xxx");
f = false;
return false;
}
ids.push(item.orderID);
});
if(f){
$("input[name=orderIds]").val(ids);
alert($("input[name=orderIds]").val());
}
原文地址:https://www.cnblogs.com/xing-nb/p/14150773.html