English 中文(简体)
j 选用所有无线电台
原标题:jQuery Select all Radio button group
  • 时间:2009-08-26 22:01:26
  •  标签:

我工作的时间很长,有几组无线电台。

底部有一个“无”无线电台。 当我选择时,我要作这样的选择,以便选择所有“N”无线电台,但我可以不去工作。 下面是该守则的简化版本:

j 质量:

$(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); 
iii

iii

表格:

<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>

我做了什么错误?

最佳回答

这两者都应发挥作用——首先,我试图保持你的风格。 随着第二位我改变风格。 你们的样本显示,一旦检查他们,就没有真正地阻止他们。

$("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");
});
问题回答

首先,在我知道的情况下,只接受X射线有效值的检查。 因此,像以下一点一样,应当做到trick。

$("#RemoveAll").change(function() {
    if ($(this).is( :checked ))
            $("input:radio.radioR").attr("checked","checked"); 

    else
            $("input:radio.radioR").removeAttr("checked"); 
    });
});

请注意,更换所有无线电台的选任人,因为添加了输入元件过滤器,实际上作为(“#id”)电话文件所必需的。 抵达 ElementById。

这应当符合你们的需要。

$("input.#RemoveAll").click(function() {

  if ($(this).attr( checked ) === "checked"){

    $("input:radio[class*= radioR ]").attr("checked","checked"); 

  }else{

    $("input:radio[class*= radioR ]").removeAttr("checked"); 

  }
});

希望它能帮助Sinan。





相关问题
热门标签