我正在處理一個長表單,它有幾個單選按鈕組。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