当我单击单个复选框时,它会更改并变为绿色.但是当我检查全天时,会检查所有复选框,但颜色不会改变.检查完整一天后,我取消选中所有仍然全天检查.我被困了,这段代码出了什么问题?
$(document).ready(function() {
$('input:checkbox[name="time"]').change(function() {
$('input:checkbox[name="time"]:not(:checked)').parent().removeClass("active");
$('input:checkbox[name="time"]:checked').parent().addClass("active");
});
});
function selectAll(source) {
checkboxes = document.getElementsByName('time');
for (var i in checkboxes)
checkboxes[i].checked = source.checked;
}Run Code Online (Sandbox Code Playgroud)
.timing {
width: 500px;
}
.timing label {
width: 100px;
display: inline-block;
border: 1px solid #ccc;
padding: 10px;
text-align: center;
cursor: pointer;
}
.timing label input {
display: block;
}
.timing label.active {
background-color: rgba(0, 204, 0, 1);
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="timing">
<label for="11:30"><input name="time" class="timess" value="11:30" id="11:30" type="checkbox">11:30</label>
<label for="12:00"><input name="time" class="timess" value="12:00" id="12:00" …Run Code Online (Sandbox Code Playgroud)