<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.item .c1{
display: none;
}
</style>
</head>
<body>
<div>
<div class="item">
<p οnclick="foo(this)">菜单一</p>
<div class="c1">111111</div>
</div>
<div class="item">
<p οnclick="foo(this)">菜单二</p>
<div class="c1">111111</div>
</div>
<div class="item">
<p οnclick="foo(this)">菜单三</p>
<div class="c1">11111111</div>
</div>
</div>
</body>
<script>
function foo(self) {
var eles = document.getElementsByClassName('c1');
for (var i=0;i<eles.length;i++){
eles[i].style.display = 'none';
}
self.nextElementSibling.style.display = 'block'
}
</script>
</html>
寻找dom标签的练习(菜单隐藏)
最新推荐文章于 2024-09-12 16:51:37 发布