如何使用javascript取消选中数组中的单选按钮

How do I un check a radio button within the input box. I've been trying to uncheck this radio button with javascript but I can't seem to be able to do it when its inside an array

this is the code that I want to un check with javascript

<?php
    for($i = 0; $i < 3; $i ++){
        $num = rand(0,2);
        for($j = 0; $j < 3; $j++){
            if($num){
                $check = 'checked';
            }else
                $check='';
            echo '<input name="acc['.$i.']" type="radio" '.$check.'>';
        }
        echo '<br/>';

    }
?>

I've tried with this javascript but I don't know how to point to the actual radio button to uncheck

$(':radio').mousedown(function(e){
    var $self = $(this);
    if( $self.is(':checked') ){
        var uncheck = function(){
            setTimeout(function(){
                $self.removeAttr('checked');
            },0);
        };
        var unbind = function(){
            $self.unbind('mouseup',up);
        };
        var up = function(){
            uncheck();
            unbind();
        };
        $self.bind('mouseup',up);
        $self.one('mouseout', unbind);
    }
});

So you have some rows, each row has 3 radios.

  • One radio can be togglable
  • If a user selects a radio in one row, all radios from other rows should become "unchecked":

var $radios = $(":radio");

$radios.on("mouseup", function(e) {

  var name  = $(this).prop("name");

  // Make togglable
  if(this.checked){
    setTimeout($.proxy(function() {
      this.checked = false;
    }, this),0);
  }
  
  // Unselect radios of other rows
  $radios.not( $("[name='"+ name +"']") ).prop("checked", false);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<br>A
<input type="radio" name="acc[0]">
<input type="radio" name="acc[0]">
<input type="radio" name="acc[0]">

<br>B
<input type="radio" name="acc[1]">
<input type="radio" name="acc[1]">
<input type="radio" name="acc[1]">

<br>C
<input type="radio" name="acc[2]">
<input type="radio" name="acc[2]">
<input type="radio" name="acc[2]">

(Note that your PHP currently makes checked all three radios inside a row! use Inspect Element to see that issue. You should fix this; but I have no clue why you use random 0,1,2... anyways so I'm unable to help you here)

</div>