關於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());
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM