我正在处理一个长表单,它有几个单选按钮组。jQuery选择所有单选按钮组
在底部有一个单选按钮“不全”。当它被选中时,我想让所有的“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);
});
});
形式:
<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>
我在做什么错?
谢谢安迪!我用你的第一个选项,它像冠军一样工作。我想取消选中单选按钮......但是花了我很长时间才弄到这么远,我觉得现在有点超过我的头:) – Chnikki 2009-08-27 14:27:39
我不认为你真的必须删除“checked”属性因为您无论如何都一次只能选择一个单选按钮,但其余代码看起来不错。 – 2010-08-24 16:11:10