HTML中用js实现select对div的隐藏与显示
HTML中用js实现select对div的隐藏与显示
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title>无标题文档</title>
</head>
<body>
<script type="text/javascript">
function change(a){
var xxx = document.getElementById("xxx");
var divArray = xxx.getElementsByTagName("div");
for (var i=0;i<divArray.length;i++) {
if (divArray[i].id == a) {
divArray[i].style.display='';
}else {
divArray[i].style.display='none';
}
}
}
</script>
<div id=xxx>
<div id=qie>
<h1>aa</h1>
aaaa
</div>
<div id=bbb style="display:none ">
bbbb
</div>
<div id=ccc style="display:none ">
cccc
</div>
</div>
<select onChange="change(this.value)">
<option value="aaa">aaa</option>
<option value="bbb">bbb</option>
<option value="ccc">ccc</option>
</select>
</body>
</html>
阅读剩余
版权声明:
作者:松跃笔记
链接:https://www.attm.cn/2024/11/07/html%e4%b8%ad%e7%94%a8js%e5%ae%9e%e7%8e%b0select%e5%af%b9div%e7%9a%84%e9%9a%90%e8%97%8f%e4%b8%8e%e6%98%be%e7%a4%ba/
文章版权归作者所有,未经允许请勿转载。
THE END