使用阵列验证 true



我正在尝试创建一个循环来验证在范围中找到的所有数字.offer_no不是 = 0,如果所有数字都返回 true,则返回 0。目前我已经写了,但我不确定如何创建验证循环。

$(".offers_container").find(".offer_no span").text()

控制台截图

像这样:

//all zeros exaple:
   function is_all_zeros(){                                       //default function return
     var out=true;
     if($(".offers_container").find(".offer_no span").length<1){  //if not found elements return false
     	 out=false;
     }
     $(".offers_container").find(".offer_no span").each(function(){
     	var this_text_int=parseInt($(this).text(), 10);           //integer value of found spin
        if(this_text_int!=0){                                     //found value not 0
        	 out=false;
        }
     });
     return out;
   }
   
   
   
   console.log(is_all_zeros());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="offers_container">
   <div class="offer_no">
       <span>0</span>
   </div>
</div>
<div class="offers_container">
   <div class="offer_no">
       <span>0</span>
   </div>
</div>

//not all zerros example:
   function is_all_zeros(){                                       //default function return
     var out=true;
     if($(".offers_container").find(".offer_no span").length<1){  //if not found elements return false
     	 out=false;
     }
     $(".offers_container").find(".offer_no span").each(function(){
     	var this_text_int=parseInt($(this).text(), 10);           //integer value of found spin
        if(this_text_int!=0){                                     //found value not 0
        	 out=false;
        }
     });
     return out;
   }
   console.log(is_all_zeros());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="offers_container">
   <div class="offer_no">
       <span>0</span>
   </div>
</div>
<div class="offers_container">
   <div class="offer_no">
       <span>4</span>
   </div>
</div>

相关内容

最新更新