我希望能够清除所有与我的父 div 下载同级的单选按钮。例如,如果选择了单选按钮选择 2 的选择 1,我想清除单选按钮选择 3 和单选按钮选择 4 中的值。
$('input:radio[name=radio-choice-2]').change(
function () {
if ($(this).val() == 'choice-1') {
$(this).parent().nextAll('div :radio').removeAttr('checked');
}
});
<form method="post" action="">
<div id="question-1">
<h4>Radio Button Choice 1</h4>
<label for="radio-choice-1-a" class="checkbox inline">Choice 1
<input type="radio" name="radio-choice-1" id="radio-choice-1-a" tabindex="2" value="choice-1" />
</label>
<label for="radio-choice-1-b" class="checkbox inline">Choice 2
<input type="radio" name="radio-choice-1" id="radio-choice-1-b" tabindex="3" value="choice-2" />
</label>
</div>
<div id="question-2" class="collapse-group">
<h4>Radio Button Choice 2</h4>
<label for="radio-choice-2-a">Choice 1</label>
<input type="radio" name="radio-choice-2" id="radio-choice-2-a" tabindex="2" value="choice-1" />
<label for="radio-choice-2-b">Choice 2</label>
<input type="radio" name="radio-choice-2" id="radio-choice-2-b" tabindex="3" value="choice-2" />
</div>
<div id="question-3" class="collapse-group">
<h4>Radio Button Choice 3</h4>
<label for="radio-choice-3-a">Choice 1</label>
<input type="radio" name="radio-choice-3" id="radio-choice-3-a" tabindex="2" value="choice-1" checked />
<label for="radio-choice-3-b">Choice 2</label>
<input type="radio" name="radio-choice-3" id="radio-choice-3-b" tabindex="3" value="choice-2" />
</div>
<div id="question-4" class="collapse-group">
<h4>Radio Button Choice 4</h4>
<label for="radio-choice-4-a">Choice 1</label>
<input type="radio" name="radio-choice-4" id="radio-choice-4-a" tabindex="2" value="choice-1" checked />
<label for="radio-choice-4-b">Choice 2</label>
<input type="radio" name="radio-choice-4" id="radio-choice-4-b" tabindex="3" value="choice-2" />
</div>
</form>