2014-10-10 120 views
0

我有一個單選按鈕組,我試圖在5個電臺檢查時顯示按鈕,但我無法做到這一點。這裏是我的代碼:單選按鈕組

$(document).ready(function() { 
    $('#vote_submit_button').hide(); 
    var unanswered = new Array(); 
    $('table').each(function() { 
     var question = $(this).find('input').attr('name'); 
     if (!$(this).find('input').is(':checked')) { 
      unanswered.push(question); 
     } 
    }); 

    if (unanswered.length > 0) { 
    } else { 
     $('#vote_submit_button').show(); 
    } 
}); 

請幫助)

+0

你可以發佈一個小提琴或發佈你的HTML? – 2014-10-10 14:18:34

回答

1

你的代碼是在文件準備在這當然點的所有的問題都沒有答案運行。

需要綁定一個事件處理單選按鈕

$(function(){ 
    $('#vote_submit_button').hide(); 
    var answered = new Array(); 
    $('input:radio').change(function(){ 
     var $this= $(this); 
     if ($this.is(':checked')){ 
     anwered.push($this.attr('name')); 
     } 

     if (answered.length == $('table').length) { 
     $('#vote_submit_button').show(); 
     } 

    }); 
}); 
+0

謝謝你!十分感謝! – nowiko 2014-10-10 14:26:21

0
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script> 
<script> 


$(document).ready(function() { 

    $(".radio").click(function(){ 

     $('#vote_submit_button').hide(); 
     var unanswered = new Array(); 
     $('table').each(function() { 
      var question = $(this).find('input').attr('name'); 
      if (!$(this).find('input').is(':checked')) { 
       unanswered.push(question); 
      } 
     }); 

     if (unanswered.length > 0) { 
     } else { 
      $('#vote_submit_button').show(); 
     } 

    }); 
}); 


</script> 

<table> 
    <tr><td> 

     <input type="radio" name="radio1" class="radio"> 

    </td></tr> 
</table> 

<table> 
    <tr><td> 

     <input type="radio" name="radio2" class="radio"> 

    </td></tr> 
</table> 

<table> 
    <tr><td> 

     <input type="radio" name="radio3" class="radio"> 

    </td></tr> 
</table> 

<table> 
    <tr><td> 

     <input type="radio" name="radio4" class="radio"> 

    </td></tr> 
</table> 

<table> 
    <tr><td> 

     <input type="radio" name="radio5" class="radio"> 

    </td></tr> 
</table> 

<input type="button" id="vote_submit_button" value="submit" style="display:none;">