如果值为1的复选框被选中,我希望值为2的复选框自动被选中。由于两个复选框具有相同的id,因此无法使用getElementById。
html:
<input type="checkbox" value="1" id="user_name">1<br>
<input type="checkbox" value="2" id="user_name">2
我感到疲倦:
var chk1 = $("input[type="checkbox"][value="1"]");
var chk2 = $("input[type="checkbox"][value="2"]");
if (chk1:checked)
chk2.checked = true;