2009-09-22 4 views
0

나는 10 개의 확인란이 있습니다. 사용자가 확인란을 선택하면 배열 및 캡처 값으로 캡처하고 싶습니다. 선택을 취소하면 값이 인쇄되지 않아야합니다.확인란의 인쇄 값

답변

1
$('#form').submit(function(e) { 
    var errorElements = [], valid = false; 

$('.checkboxgroup', this).each(function() { 
     var checkBoxes = $(':checkbox', this), oneChecked = false; 
     checkBoxes.each(function() { 
      if (!oneChecked && !$(this).is(':checked')) { 
       valid = false; 
       errorElements.push(this); 
      } else { 
       oneChecked = true; 
      } 
     }); 
    }); 

    e.preventDefault(); // cancels form submit.. remove if you dont need. 

    if (errorElements.length) { 
    // code to do what you want if it fails 
    } else { 
    // code to do what you want if it passes 
    } 


}); 

HTML :

<div class="checkboxgroup"> 

(checkbox html) 

</div> 


<div class="checkboxgroup"> 

(checkbox html) 

</div>