如果页面包含三个复选框,那么在使用asp.net和javascript从数据库中获取数据后,如果要选中一个复选框,我想禁用两个复选框
答案 0 :(得分:0)
使用承诺获取:
const checkbox1 = document.getElementById("checkbox1");
const checkbox2 = document.getElementById("checkbox2");
const checkbox3 = document.getElementById("checkbox3");
fetch("www.yourapi.com?get-data").then((response) => {
const checkbox1Checked = response.checkbox1;
const checkbox2Checked = response.checkbox2;
const checkbox3Checked = response.checkbox3;
if (checkbox1Checked) {
checkbox2.checked = false
checkbox3.checked = false
} else if (checkbox2Checked) {
checkbox1.checked = false
checkbox3.checked = false
} else if (checkbox3Checked) {
checkbox2.checked = false
checkbox3.checked = false
}
})