【发布时间】:2017-08-03 11:29:26
【问题描述】:
我正在尝试在primary checkbox 的支票上选中/取消选中secondary checkboxes。但是我的 jquery 函数不起作用。
HTML 代码:
<table id="tab" class="table">
<tr>
<td>
<input name="feature-1" class="ExtraCheckBox" type="checkbox"> Primary
</td>
<td>
<input name="feature-1" class="ChildCheckBox" type="checkbox"> Secondary
<input name="feature-1" class="ChildCheckBox" type="checkbox"> Secondary
</td>
</tr>
</table>
jQuery 代码:
$(document).on('change', '.ExtraCheckBox', function() {
var checked = $(".ExtraCheckBox").closest('div.icheckbox_square-grey').hasClass("checked");
console.log(checked);
if (checked) {
$("#tab > tr >td.ChildCheckBox").each(function() {
$(this).prop("checked", true);
});
} else {
$("#tab > tr >td.ChildCheckBox").each(function() {
$(this).prop("checked", false);
});
}
});
请在此处找到 js fiddle 演示:Link
任何建议,请!
【问题讨论】:
-
$(this).iCheck('check');和 $(this).iCheck('uncheck');应该有帮助
-
@MehravishTemkar:检查参考链接。