jQuery选择所有单选按钮组

Chn*_*kki 2 jquery radio-button

我正在处理一个有几个单选按钮组的长表单.

底部有一个单选按钮"No All".当它被选中时,我想这样做,以便选择所有"N"单选按钮,但我不能让它工作.这是代码的简化版本:

jQuery的:

$(document).ready(function(){
//initially hide the Remove All Questions
$("div.#removeAllquest").hide();

////////////  Show Remove All Questions if radio button selected 
$("input.#RemoveAll").click(function() {
  if ($(this).is(':checked'))
    $("input:radio [class*='radioR']").attr("checked",true); 
  else
$("input:radio [class*='radioR']").attr("checked",false); 
});
Run Code Online (Sandbox Code Playgroud)

});

形成:

<table>
  <tr>
    <td>Y<input type="radio" name="row1" value="row1col1" class="q123col1"></td>
    <td>N<input type="radio" name="row1" class="radioR" value="row1col2"></td>
    <td>M<input type="radio" name="row1" value="row1col3" class="q123col3"></td>
  </tr>
  <tr>
    <td>Y<input type="radio" name="row2" value="row2col1" class="q123col1"></td>
    <td>N<input type="radio" name="row2" class="radioR" value="row2col2"></td>
    <td>M<input type="radio" name="row2" value="row2col3" class="q123col3"></td>
  </tr>
  <tr>
    <td>Y<input type="radio" name="row3" value="row3col1" class="q123col1"></td>
    <td>N<input type="radio" name="row3" class="radioR" value="row3col2"></td>
    <td>M<input type="radio" name="row3" value="row3col3" class="q123col3"></td>
  </tr>
  <tr> 
    <td colspan="2">No All </td>
    <td>
      <input name="RemoveAll" id="RemoveAll" type="radio" value="Y">
    </td>
  </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

And*_*ell 11

这两个都应该工作 - 第一个我试图保持你的风格.随着第二次我改变了风格.对于您的样本,一旦检查完毕,就没有办法取消选中它们.

$("input.#RemoveAll").click(function() {
    if ($(this).is(':checked'))
        $("input:radio.radioR").attr("checked", "checked");
    else
        $("input:radio.radioR").removeAttr("checked");
});

$("#RemoveAll").click(function() {
    if ($(this).is(':checked'))
        $(".radioR").attr("checked", "checked");
    else
        $(".radioR").removeAttr("checked");
});
Run Code Online (Sandbox Code Playgroud)