如果和/或被選中,我試圖保持#b0禁用和未選中狀態。如果取消選中或#b1#b2#b0#b1#b2
let boxes = $('#b1, #b2');
boxes.click(function() {
if (boxes.filter(':checked').length > 0) {
$("#b0").prop("disabled", this.checked).prop({"checked": false}, this.checked);
}
})
<label for="b0">1</label>
<input id="b0" name="name0" type="checkbox">
<label for="b1">2</label>
<input id="b1" name="name1" type="checkbox">
<label for="b2">3</label>
<input id="b2" name="name2" type="checkbox">
小提琴
uj5u.com熱心網友回復:
您可以啟用else塊中的復選框,如下所示:
let used_for_contact = $('#b1, #b2');
used_for_contact.click(function() {
if (used_for_contact.filter(':checked').length > 0) {
$("#b0").prop("disabled", true).prop("checked", false);
} else {
$("#b0").prop("disabled", false);
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<input id="b0" name="info_for_contact" type="checkbox">
<label for="b0">1</label>
<input id="b1" name="info_for_contact" type="checkbox">
<label for="b1">2</label>
<input id="b2" name="info_for_contact" type="checkbox">
<label for="b2">3</label>
小提琴
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/427843.html
