我有單選按鈕組和子組。我想要達到的目的是在選擇主組單選按鈕時無法使用子組,並且選擇其他組時,禁用子組並取消檢查子組的所有單選按鈕。禁用單選按鈕組
下面有一個例如:
<form name='nameForm'>
<input name='category' type='radio' value='a' >
<input name='category' type='radio' value='b' >
<input name='subcategory_b' type='radio' disabled value='1' >
<input name='subcategory_b' type='radio' disabled value='2' >
<input name='subcategory_b' type='radio' disabled value='3' >
<input name='category' type='radio' value='c' >
</form>
的想法是,當我ckeck單選按鈕B,單選按鈕組子類別b爲啓用。但是,如果我然後檢查單選按鈕a或c,應該禁用子類別b並取消選中
想法是禁用 - 取消選中或啓用整個子組,而不手動禁用值爲1,2或3的單選按鈕,因爲這些單選按鈕是按需構建的
記得引用您的字符串。 'if(this.value!='b')' –
在嘗試此操作之前,我有一個問題。如何: if(this.value!= b){('input [name = category]')。attr('disabled','disabled'); } else { $('input [name = category]')。removeAttr('disabled'); } 將禁用subategory_b?,啓用它並將其刪除... 其只是爲了學習 –
其實它並沒有改變subcategory_b ...我做了一些改變,但是這個想法很好用!這裏是我的修改: $('input [name = category]')。change(function(){ if(this.value!='b'){$('input [name = subcategory_b]') 。'tr'('disabled','disabled'); \t \t $('input [name = subcategory_b]')。attr('checked',false); } else {$('input [name = subcategory_b] ').removeAttr('disabled'); } }); –