关于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