<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<style type="text/css">
li{
float: left;
list-style: none;
text-align: center;
width: 100px;
line-height: 100px;
background: #7CFC00;
border:#0000FF 1px solid;
}
div{
width: 300px;
line-height: 100px;
background: #FFFF00;
text-align: center;
}
</style>
</head>
<body>
<li onclick="func(0)">点击1</li>
<li onclick="func(1)">点击2</li>
<li onclick="func(2)">点击3</li>
<div>
我这个是个div <br />
换一行就可以了
</div>
<div style="display: none;">
这个是div2 <br />
同样换一行就可以了
</div>
<div style="display: none;">
这个是div3 <br />
换一行就行了
</div>
<script type="text/javascript">
function func(a){
//获取整个集合
var divs = document.getElementsByTagName('div');
for(var i=0;i<divs.length;i++){
if(a == i){
divs[i].style.display='block';
}else{
divs[i].style.display='none';
}
}
}
</script>
</body>
</html>