0

我有这样的事情:

    <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-leveldiv 上方的复选框。如何做到这一点?(因为我想.pricing-level在它们都未选中时隐藏 div。)

4

4 回答 4

3

尝试:

  if($('form > :checked').length == 0){
     //none are checked
  }

或更准确地说,您可以这样做:

  if(!$('form > input:checked').length){ //since you don't want to target by name
于 2013-09-25T04:26:26.820 回答
1

尝试

if($('input[name="vehicle"]:chekced') == 0){

}
于 2013-09-25T04:27:35.070 回答
1
if($('form > :checked').length === 0){
 // Your action
}

这只检查元素的直接子form元素,因此,跳过里面的所有子元素.pricing-levels

于 2013-09-25T04:30:26.130 回答
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();   
}
});

这是演示:http: //jsfiddle.net/ssfQf/

于 2013-09-25T04:43:27.053 回答