1 回答
TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超7個(gè)贊
您可以簡(jiǎn)單地將事件偵聽(tīng)器添加到選擇的“更改”事件中,并根據(jù)選擇的值更改復(fù)選框的“已選中”屬性
html:
<html>
<head></head>
<body>
<select id="select">
<option value="a" selected>something</option>
<option value="b">check</option>
</select>
<label>
<input id="checkbox" type="checkbox">
Checkbox
</label>
<script>
let select = document.getElementById("select");
let checkbox = document.getElementById("checkbox");
select.addEventListener("change", function () {
checkbox.checked = select.value !== "a";
});
</script>
</body>
</html>
添加回答
舉報(bào)
