js实现淘宝选项卡效果
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
ul{
overflow: hidden;
list-style: none;
}
li{
float: left;
margin-right: 10px;
border: 1px solid #333;
cursor: pointer;
}
.box{
width: 300px;
height: 200px;
border: 1px solid red;
display: none;
}
.active{
background-color: #0084BB;
}
</style>
<script type="text/javascript">
window.onload = function(){
var aLi = document.getElementsByTagName('li');
var aBox = document.getElementsByClassName('box');
// console.log(aLi,aBox);
for(var i = 0; i < aLi.length; i++){
aLi[i].index = i;
aLi[i].onclick = function(){
for(var i = 0; i < aLi.length; i++){
aLi[i].className = '';
aBox[i].style.display = 'none';
}
aLi[this.index].className = 'active';
aBox[this.index].style.display = 'block';
}
}
}
</script>
</head>
<body>
<ul>
<li class="active">标题1</li>
<li>标题2</li>
<li>标题3</li>
</ul>
<div class="box" style="display: block;">标题一内容</div>
<div class="box">标题二内容</div>
<div class="box">标题三内容</div>
</body>
</html>
本文来自博客园,作者:JackieDYH,转载请注明原文链接:https://www.cnblogs.com/JackieDYH/p/17634836.html