<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<select size="4">
<option onclick="showDiv('1')" selected>场景添加</option>
<option onclick="showDiv('2')" >场景更新</option>
<option onclick="showDiv('3')">替换场景</option>
<option onclick="showDiv('4')">状态相关</option>
</select>
<div id="1">
<p style="background-color: pink;width:200px ;display: block; height: 200px;"></p>
</div>
<div id="2" style="display: none">
<p style="background-color: red;width:200px ;height: 200px;"></p>
</div>
<div id="3">
<p style="background-color: black;width:200px ;height: 200px;"></p>
</div>
<div id="4"style="display: none">
<p style="background-color: yellow;width:200px ;height: 200px;"></p>
</div>
</body>
<script>
let divs=document.querySelectorAll('div');
let showDiv=(str)=>{
for(let div of divs){
div.style.display="none";
}
document.getElementById(str).style.display = "block";
}
</script>
</html>
不想初始展示哪个盒子 就把哪个盒子style="display: none"