tab栏切换仿写
pink 视频
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>tab pink 视频</title>
<link rel="stylesheet" href="./tab.css">
<script src="./tab.js"></script>
</head>
<body>
<div class="tab">
<div class="tabList">
<ul>
<li class="current">商品介绍</li>
<li>规格与包装</li>
<li>售后保障</li>
<li>商品评价</li>
<li>手机社区</li>
</ul>
</div>
<div class="tabcon">
<div class="item" style="display: block;">商品</div>
<div class="item">规则</div>
<div class="item">售后</div>
<div class="item">评价 </div>
<div class="item">手机</div>
</div>
</div>
<script src="./tab.js"></script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>tab pink 视频</title>
<link rel="stylesheet" href="./tab.css">
<script src="./tab.js"></script>
</head>
<body>
<div class="tab">
<div class="tabList">
<ul>
<li class="current">商品介绍</li>
<li>规格与包装</li>
<li>售后保障</li>
<li>商品评价</li>
<li>手机社区</li>
</ul>
</div>
<div class="tabcon">
<div class="item" style="display: block;">商品</div>
<div class="item">规则</div>
<div class="item">售后</div>
<div class="item">评价 </div>
<div class="item">手机</div>
</div>
</div>
<script src="./tab.js"></script>
</body>
</html>
var tabList=document.querySelector(".tabList");
var Liall=tabList.querySelectorAll("li");
var items=document.querySelectorAll('.item')
for(var i=0;i<Liall.length;i++){
Liall[i].setAttribute('index',i);
Liall[i].onclick=function(){
for(var i=0;i<Liall.length;i++){
Liall[i].className="";
}
this.className="current";
var index= this.getAttribute('index');
console.log(index);
for(var i=0;i<items.length;i++){
items[i].style.display='none';
}
items[index].style.display='block';
}
}