Я хочу установить все флажки после установки флажка «Выбрать все», и наоборот, если я выберу все флажки один за другим, флажок «Выбрать все» должен быть установлен автоматически. Если я сниму отметку с любого из его дочерних флажков, то флажок «Выбрать все» также должен быть снят.
В моем коде все работает, кроме одного: если я выберу все флажки один за другим, флажок «Выбрать все» должен быть автоматически установлен. Может ли кто-нибудь помочь мне сделать эту вещь работоспособной для меня. Для справки я привожу здесь свой код файла (код HTML и Javascript), чтобы вы могли протестировать его на своем локальном компьютере .:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function () {
$("#ckbCheckAll").click(function () {
$(".checkBoxClass").prop('checked', $(this).prop('checked'));
});
$(".checkBoxClass").change(function(){
if (!$(this).prop("checked")){
$("#ckbCheckAll").prop("checked",false);
}
});
});
</script>
</head>
<body>
<input type="checkbox" id="ckbCheckAll" /> Check All
<p id="checkBoxes">
<input type="checkbox" class="checkBoxClass" id="Checkbox1" />
<br />
<input type="checkbox" class="checkBoxClass" id="Checkbox2" />
<br />
<input type="checkbox" class="checkBoxClass" id="Checkbox3" />
<br />
<input type="checkbox" class="checkBoxClass" id="Checkbox4" />
<br />
<input type="checkbox" class="checkBoxClass" id="Checkbox5" />
<br />
</p>
</body>
</html>