【发布时间】:2014-01-27 04:03:00
【问题描述】:
如果选中值为 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;
【问题讨论】:
-
你应该给不同的元素不同的id。
-
不能与多个元素共享同一个ID!!!
标签: javascript jquery checkbox