我試圖在primary checkbox
的檢查上檢查/取消選中secondary checkboxes
。但我的jQuery功能不起作用。使用jquery檢查icheck上的所有checboxes
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演示小提琴這裏:Link
任何建議,請!
$(this).iCheck('check');和$(this).iCheck('uncheck');應該幫助 –
https://github.com/fronteed/icheck#methods –
@MehravishTemkar:檢查參考鏈接。 – 06011991