我有麻烦创建时,在同一线路上的其他选择取消选中当另一个复选框被选中
function uncheck1(){
document.getElementById("check1").checked = true;
document.getElementById("check2").checked = false;
document.getElementById("select").disabled = true;
}
function uncheck2(){
document.getElementById("check1").checked = false;
document.getElementById("check2").checked = true;
document.getElementById("select").disabled = false;
}
<form name="form" action="action.php" method="post">
<table>
<tr>
<td>
<input type="hidden" value="Carrizo J." name="player[]" />
</td>
<td>
<label>Carrizo J.</label>
</td>
<td>
<input id="check1" onclick="uncheck1()" type="checkbox" name="titolare[]" value="0" checked="" />
</td>
<td>
<input id="check2" onclick="uncheck2()" type="checkbox" name="titolare[]" value="1" />
</td>
<td>
<select id="select" name="ordine[]" disabled>
<option>1</option>
<option>2</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="hidden" value="Handanovic S." name="player[]" />
</td>
<td>
<label>Handanovic S.</label>
</td>
<td>
<input id="check1" onclick="uncheck1()" type="checkbox" name="titolare[]" value="0" checked="" />
</td>
<td>
<input id="check2" onclick="uncheck2()" type="checkbox" name="titolare[]" value="1" />
</td>
<td>
<select id="select" name="ordine[]" disabled>
<option>1</option>
<option>2</option>
</select>
</td>
</tr>
<tr>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
</table>
</form>
由于并且,显然,它只适用于第一行。 如果我检查了正确的一个,则左边的一个未被选中,并且选择被启用。 然后,如果我检查左侧,右侧没有选中,选择被禁用。
有没有办法能够对其他24行做同样的事情,而不必为每个行写两个函数?
为什么不使用无线电输入呢? –
一组具有相同名称的单选按钮将完全符合您的要求并被大家理解。另外ID需要是唯一的 – mplungjan
单选按钮是有意义的......除非它是作业? –