这里检查是HTML:为什么复选框没有被jQuery的
<input id="globalchecker" type="checkbox"/>
<input type="checkbox" class="childcheckboxes" />
<input type="checkbox" class="childcheckboxes" />
<input type="checkbox" class="childcheckboxes" />
<input type="checkbox" class="childcheckboxes" />
,这里是jQuery的:
$('#globalchecker').on('click', function() {
if($('#globalchecker').is(":checked")){
$('.childcheckboxes:checkbox').prop('checked',true);
}
else{
$('.childcheckboxes:checkbox').prop('checked', false);
}
});
点击 '#globalchecker' 复选框,在” .childcheckboxes时
'不检查/不检查。我究竟做错了什么?
你的代码工作fine.Here是小提琴:https://jsfiddle.net/aaenbect/ –
你应该使用'change'事件,而不是'click'事件 –
你的代码为我完美工作!!!!!! –