2012-01-18 59 views
0

我有一个问题表单,我想验证使用jQuery。我的形式如下:如何检查多个单选按钮选择?

 <form id="question_answer_form" action="submit_answers.php" method="post">  
      <table class="zebra-striped"> 
       <tr> 
        <td >Question 1</td> 

        <td> 
         <input type="radio" name="question_answer1" value="1"> Yes 
         <input type="radio" name="question_answer1" value="0"> No 
        </td> 
       </tr> 
       <tr> 
        <td >Question 2</td> 
        <td> 
         <input type="radio" name="question_answer2" value="1"> Yes 
         <input type="radio" name="question_answer2" value="0"> No 
        </td> 
       </tr> 
       <tr> 
        <td >Question 3</td> 
        <td> 
         <input type="radio" name="question_answer3" value="1"> Yes 
         <input type="radio" name="question_answer3" value="0"> No 
        </td> 
       </tr> 
       <tr> 
        <td colspan="2"><input class="btn success" type="button" value="Submit" id="questions"/></td> 
       </tr> 
      </table> 
     </form> 

jQuery的通话

$("#questions").click(function (e) { 
     e.preventDefault(); 

     // Check radio button status and notify...; 
    }); 

有什么建议?

回答

3

添加到每个无线电一些类例如 “test_radio” 然后检查

$( “test_radio:检查”)。长度> 1

+0

这很好,谢谢! – Paul 2012-01-18 13:50:32

+0

不客气。 – Ph0en1x 2012-01-18 13:56:39