用数组验证真
Verify true with array
我正在尝试创建一个循环来验证在 .offer_no 范围内找到的所有数字都不是 = 0,如果所有数字 = 0,则 return 为真。目前我已经写了,但我不确定如何创建验证循环。
$(".offers_container").find(".offer_no span").text()
Console Screenshot
像这样:
//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>
我正在尝试创建一个循环来验证在 .offer_no 范围内找到的所有数字都不是 = 0,如果所有数字 = 0,则 return 为真。目前我已经写了,但我不确定如何创建验证循环。
$(".offers_container").find(".offer_no span").text()
Console Screenshot
像这样:
//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>