Я использую следующий пример HTML-кода ниже. С jQuery я не уверен, как реализовать "Выбрать/Отменить выбор всех", используя id="select-all"
чтобы установить/снять все флажки ниже, где name="p_v01"
<span style="font-size:8px;">Select All</span><br>
<input type="checkbox" name="select-all" id="select-all">
<span style="font-weight:bold;font-size:16px;padding-left:20px;">Emps</span>
<table summary="" role="presentation" class="checkbox_group">
<tbody>
<tr>
<td>
<input type="checkbox" id="P2_EMP_CB_0" name="p_v01" value="ANALYST">
<label for="P2_EMP_CB_0">ANALYST</label>
</td>
<td>
<input type="checkbox" id="P2_EMP_CB_1" name="p_v01" value="CLERK">
<label for="P2_EMP_CB_1">CLERK</label>
</td>
<td>
<input type="checkbox" id="P2_EMP_CB_2" name="p_v01" value="MANAGER">
<label for="P2_EMP_CB_2">MANAGER</label>
</td>
<td>
<input type="checkbox" id="P2_EMP_CB_3" name="p_v01" value="PRESIDENT">
<label for="P2_EMP_CB_3">PRESIDENT</label>
</td>
<td>
<input type="checkbox" id="P2_EMP_CB_4" name="p_v01" value="SALESMAN">
<label for="P2_EMP_CB_4">SALESMAN</label>
</td>
</tr>
</tbody>
Вы можете использовать:
$('#select-all').click(function() {
$('input[name="p_v01"]').prop('checked',this.checked);
});
Попробуй это:
$('#select-all').on('change', function() {
$('input[name="p_v01"]').prop('checked', this.checked);
});
change
в #select-all
$('input[name="p_v01"]')
check/uncheck
это приводит к true/false
.Использовать ниже jQuery
<script>
$(document).ready(function(){
$('#select-all').click(function(){
$('input[name="p_v01"]').attr("checked",$(this).is(':checked'));
});
});
</script>