2 回答
TA贡献1804条经验 获得超7个赞
请尝试以下示例
document.querySelector("select#location").addEventListener("change", () => {
display(event.target.value);
});
const boxs = document.querySelectorAll("div.box");
function display(value) {
for (const box of boxs) {
if (box.classList.contains(value)) {
box.classList.remove("hide");
} else {
box.classList.add("hide");
}
}
}
display("A");
.hide {
display: none;
}
<div>
<select id="location">
<option value="A">Location A</option>
<option value="B">Location B</option>
<option value="C">Location C</option>
</select>
</div>
<div class="box A">Tide Location A</div>
<div class="box B">Tide Location B</div>
<div class="box C">Tide Location C</div>
TA贡献2036条经验 获得超8个赞
对 div使用 CSS显示属性
function myFunction() {
var x = document.getElementById("myDIV");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
- 2 回答
- 0 关注
- 154 浏览
添加回答
举报