我在写一些HTML时遇到了一些问题,并且想知道是否有人可以提供帮助。
我有6个复选框,如下所示
周一 星期二 星期三 星期四 星期五 全天
HTML如下:
<input type="checkbox" name="monday" value="1" id="monday" />
<input type="checkbox" name="tuesday" value="1" id="tuesday" />
<input type="checkbox" name="wednesday" value="1" id="wednesday" />
<input type="checkbox" name="thursday" value="1" id="thursday" />
<input type="checkbox" name="friday" value="1" id="friday" />
<input type="checkbox" name="alldays" value="1" id="alldays" />
我已经有一些jquery,当选择“All Days”时,检查所有其余的复选框。
我现在拥有的jQuery如下:
<script>
$(function(){
$("#alldays").change(function(){
if (this.checked) {
$("input:checkbox.child").attr("checked", "checked");
}
else {
$("input:checkbox.child").removeAttr("checked");
}
});
});
</script>
我想添加另一个jQuery,如果勾选了所有六个复选框,并且有人点击其中一个工作日,则“All Days”复选框将自动取消选中。
请有人帮我解决这个问题。
干杯
答案 0 :(得分:0)
试试这个:
$("#alldays").change(function(){
$("input:checkbox.child").attr("checked", this.checked);
});
$("input:checkbox.child").change(function() {
if ($("#alldays").attr("checked")) {
$("#alldays").attr("checked", false);
}
});