显示单选按钮的编号 即时检查


show number of radio button checked instantaneous

>我在 while 循环中有名称为 2d 数组的单选按钮。我想显示单击时选中的单选按钮的数量。

我的单选按钮

        $n=0;
        while($row= mysqli_fetch_row($rs)){?>
        <form name="myfm" id="myfm" method="post" action="Quizn.php">
        <table width=100%> <tr> <td width=30><td></td></td></tr> <table border=0>
        <?php $n=$n+1; ?>
        <tr><td>Question <?php echo $n.") "; echo $row[2]; ?></td></tr>
        <tr><td class=style8>A. <input type="radio" name="ques['<?php echo $n; ?>'][]" value=1><?php echo $row[3]; ?></td></tr>
        <tr><td class=style8>B. <input type="radio" name="ques['<?php echo $n; ?>'][]" value=2><?php echo $row[4];?></td></tr>
        <tr><td class=style8>C. <input type="radio" name="ques['<?php echo $n; ?>'][]"  value=3><?php echo $row[5];?></td></tr>
        <tr><td class=style8>D. <input type="radio" name="ques['<?php echo $n; ?>'][]"  value=4><?php echo $row[6];?></td></tr>
        <input type="hidden" name="ques['<?php echo $n; ?>'][]" value="0" />
        <input type="hidden" value="<?php echo $row[0]; ?>" name="qid[]" />  
  <?php }
        echo "<tr><td><input type=submit name=submit id='result' value='Get Result'></form>";
        ?>
        </table></table>
        </form>
   <p>Clicked:</p> <p id="clicked">0</p>

JavaScript

$("input:radio").click(function () {
var totalRd = $('table').find(':not(.pend) > input:radio:checked').length;
$("#totalRd .rd-count").html(totalRd);
});

如果您知道解决方案,请帮助我。谢谢

有一些假设,尝试这样

<?php
    if(isset($_POST['submit'])){
        echo "<pre>";
        print_r($_POST);
        echo "</pre>";
    }
?>
<form method="post" action="">
<?php for ($i=0; $i < 3 ; $i++) { ?>
    <br>
    A<input type="radio" name="ques[<?php echo $i;?>][]" value=1>
    B<input type="radio" name="ques[<?php echo $i;?>][]" value=2>
    C<input type="radio" name="ques[<?php echo $i;?>][]" value=3>
    D<input type="radio" name="ques[<?php echo $i;?>][]" value=4>
<?php } ?>
<br>
<input type="submit" name="submit" value="submit">
</form>

http://screencast.com/t/HEVSPR7yVR

http://screencast.com/t/rQSpXiJAMg

我建议不要在这里使用数组name="ques[<?php echo $i;?>][]"而只是使用name="ques[<?php echo $i;?>]"来干净清晰

试试这个

$(":radio").on( 'click', function() {
    count = $(':radio:checked').length;
    alert(count);
});