【发布时间】:2014-07-14 20:00:54
【问题描述】:
我想在选中“选择所有”复选框后查看所有复选框。我已经阅读了关于 SO 的各种线程,但无法获得预期的 o/p。
相关问题:-Select all checkboxes with jQuery
这是我尝试过的。
<div class="row-fluid" id="set_alarm">
<label class="checkbox inline"><input type="checkbox" id="select_all"><b>Select All</b></label><br>
<label class="checkbox inline days"><input type="checkbox" id="Mon"><b>Mon</b></label>
<label class="checkbox inline days"><input type="checkbox" id="Tue"><b>Tue</b></label>
......
......
</div>
jQuery
$('#select_all').change(function() {
var checkboxes = $(this).closest('.days').find(':checkbox');
if($(this).is(':checked')) {
checkboxes.attr('checked', 'checked');
} else {
checkboxes.removeAttr('checked');
}
});
【问题讨论】:
-
看看我的答案,它会做你想做的事,当你选择另一个框时,它会取消选中“全选”框。