考虑以下标记:
<form>
<div class="project">
<ul class="choice">
<li><label for="firstchoice_1">First choice</label><input type="radio" name="firstchoice" value="1" id="firstchoice_1" /></li>
<li><label for="secondchoice_1">Second choice</label><input type="radio" name="secondchoice" value="1" id="secondchoice_1" /></li>
</ul>
</div>
<div class="project">
<ul class="choice">
<li><label for="firstchoice_2">First choice</label><input type="radio" name="firstchoice" value="2" id="firstchoice_2" /></li>
<li><label for="secondchoice_2">Second choice</label><input type="radio" name="secondchoice" value="2" id="secondchoice_2" /></li>
</ul>
</div>
</form>
我想要做的是,每当选择一个
.project
组中的单选按钮时,禁用该组中的另一个单选按钮(因此每个组中只能选择First choice
或Second choice
)。我知道如何在一个特定情况下禁用一个特定的单选按钮,但我不知道如何将其推广到所有这些.project
组,因为它们可能有上百个。编辑:请注意,只能选择整个
First choice
(反之亦然)。已经使用了相同的名称。整个标记中都使用了相同的name
属性。只有两个不同的name
。