var top1 = document.getElementById('top').getElementsByTagName('li')
var bot1 = document.getElementById('bottom').getElementsByTagName('div')
console.log(bot1);
for(var i= 0;i<top1.length;i++){
top1[i].setAttribute('index',i)
top1[i].onclick = function(){
for(var i= 0;i<top1.length;i++){
top1[i].className = ''
}
this.className = 'current'
var index = this.getAttribute('index')
for(var i= 0;i<top1.length;i++){
bot1[i].style.display = 'none'
}
bot1[index].style.display = 'block'
}
}
.yifu{
width: 300px;
height: 300px;
background-color: darkkhaki;
}
.fruit{
width: 500px;
height: 500px;
background-color: cyan;
}
.phone{
width: 600px;
height: 300px;
background-color: blue;
}
.block{
display: block
}
.item{
display: none;
}
.max_con{
width: 500px;
height: 500px;
margin: 0 auto;
}
li{
list-style: none;
}
#top{
width: 400px;
height: 50px;
}
.bottom>div{
width: 50px;
height: 50px;
text-align: center;
line-height: 50px;
}
#bottom{
width: 400px;
height: 50px;
}
#top>li{
float: left;
width: 50px;
height: 50px;
text-align: center;
line-height: 50px;
}
.current{
background-color: yellow;
}
<div class="max_con">
<div id="top">
<li class="current">手机</li>
<li>水果</li>
<li>服装</li>
</div>
<div id="bottom">
<div class="item phone" style="display: block;">手机</div>
<div class="item fruit">水果</div>
<div class="item yifu">服装</div>
</div>
</div>