[英]how to check/uncheck only specific checkbox if there are multiple checkboxes
[英]Checkbox onclick uncheck other checkboxes
我有6個復選框,每個工作日一個,一個說“全部”。
我希望能夠做的是取消選中所有其他框,如果有人點擊“全部”復選框,如果這是有道理的。
例如,如果有人點擊星期一和星期三...然后他們進來並單擊“全部”復選框,則應取消選中星期一和星期三復選框。
干杯,
這不是你想要的,但似乎更明智。
HTML
<input type="checkbox" id="chkAll" />
<br />
<input type="checkbox" id="chkMonday" class="child" />
<input type="checkbox" id="chkTuesday" class="child" />
<input type="checkbox" id="chkWednesday" class="child" />
<input type="checkbox" id="chkThursday" class="child" />
<input type="checkbox" id="chkFriday" class="child" />
<input type="checkbox" id="chkSaturday" class="child" />
<input type="checkbox" id="chkSunday" class="child" />
jQuery的
$(function(){
$("#chkAll").change(function(){
if (this.checked) {
$("input:checkbox.child").attr("checked", "checked");
}
else {
$("input:checkbox.child").removeAttr("checked");
}
});
});
查看工作演示
請參閱處理子項復選框的更新版本 。
jquery和這樣的代碼應該這樣做。
$('#all-id').change(function(){
if($('#all-id').is(':checked')){
if($('#monday-id').is(':checked')){
$('#monday-id').attr('checked', false);
} else {
$('#monday-id').attr('checked', true);
}
// etc
}
});
您可能希望將所有ID放入數組並設置循環或播放文檔結構后,可以輕松循環所有這些復選框
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.