【发布时间】:2014-09-27 19:52:07
【问题描述】:
我有一个 html 代码,其中分别有两个父复选框及其子复选框。 Onclick of parent 复选框应选中属于该父级的子级。就我而言,如果我选中父复选框,则会选中所有子复选框。我知道这是类名的问题,我可以用两个不同的类名命名并解决问题。但我无法更改类名。应该是一样的。我该如何解决这个问题??
index.html
Parent1<input name="parent" class="pc-box" type="checkbox">
Child 1<input class="check" name="child" type="checkbox">
Child 2<input class="check" name="child" type="checkbox">
Child 3<input class="check" name="child" type="checkbox">
<br>
Parent2<input name="parent" class="pc-box" type="checkbox" >
Child 1 <input class="check" name="child" type="checkbox">
Child 2 <input class="check" name="child" type="checkbox">
Child 3 <input class="check" name="child" type="checkbox">
index.js
$(document).ready(function() {
$(".pc-box").click(function() {
if (this.checked) {
('.check').prop('checked',$(this).prop('checked'));
}
});
});
【问题讨论】:
标签: javascript jquery html checkbox