我有这样的事情:
<form action="">
<input type="checkbox" name="vehicle" value="Bike">Lesson Audio / <span class="pricing-box-price">$19.95 USD</span><br>
<input type="checkbox" name="vehicle" value="Bike">Lesson PDFs / <span class="pricing-box-price">$19.95 USD</span><br>
<input type="checkbox" name="vehicle" value="Bike">Review Audio / <span class="pricing-box-price">$19.95 USD</span><br>
<div class="pricing-levels">
<p>Which level would you like? (Click all that apply)</p>
<input type="checkbox" name="vehicle" value="Bike">Level 1<br>
<input type="checkbox" name="vehicle" value="Bike">Level 2<br>
<input type="checkbox" name="vehicle" value="Bike">Level 3<br>
<input type="checkbox" name="vehicle" value="Bike">Level 4<br>
<input type="checkbox" name="vehicle" value="Bike">Level 5<br>
<input type="checkbox" name="vehicle" value="Bike">Level 6<br>
<input type="checkbox" name="vehicle" value="Bike">Level 7<br>
</div>
</form>
我想在取消选中所有前三个复选框时执行操作(.pricing-level
div之上的那些。如何实现?(因为我想隐藏.pricing-level
div一切都未经检查。)
答案 0 :(得分:3)
尝试:
if($('form > :checked').length == 0){
//none are checked
}
或者更确切地说,你可以这样做:
if(!$('form > input:checked').length){ //since you don't want to target by name
答案 1 :(得分:1)
尝试
if($('input[name="vehicle"]:chekced') == 0){
}
答案 2 :(得分:1)
if($('form > :checked').length === 0){
// Your action
}
这只检查form
元素的直接子元素,因此跳过.pricing-levels
内的所有元素
答案 3 :(得分:0)
您可以使用以下内容:
if($('form > :checked').length == 0){
var x = $('form > :checked').length;
console.log(x);
jQuery('.pricing-levels').hide();
}
jQuery('form > input[name=vehicle]').change(function(){
if($('form > :checked').length == 0){
var x = $('form > :checked').length;
console.log(x);
jQuery('.pricing-levels').hide();
}else{
jQuery('.pricing-levels').show();
}
});