tap栏切换 js

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
<div id="box">
	<div class="box-top">
		<span class="active">电影</span>
		<span class="">综艺</span>
		<span class="">电视剧</span>
	</div>
	<div class="box-foot">
		<ul>
			<li class="current">电影</li>
			<li>电视剧</li>
			<li>综艺</li> 
		</ul>
	</div>
</div>
	
</body>
</html>
*{
       	  margin: 0;
       	  padding: 0;
       }
       li{
       	list-style: none;
       }
       #box{
       	 margin: 200px;
       	  border: 1px solid #ccc;
       	  width: 600px;
       }
       .box-top{
           width: 615px;
           height: 60px; 
            border-bottom: 1px solid #ccc;
       }
       .box-top span{
       	display: inline-block;
       	width: 32%;
       	height: 100%;
       	line-height: 60px;
       	text-align: center;
       }
       .box-foot{
       	 padding: 10px;
       	 height: 200px;
       	 font-size: 30px;
       }
       .active{
       	 color:#fff;
       	 background-color: #bf35bd;
       	 font-size: 20px;
       	 
       }
       .current{
       	  font-weight: 600;
       	  display: block;
       }
       li{
       	display: none;
       }
        var  box=document.getElementById('box');
	var spans=box.getElementsByTagName("span");
	var lis=box.getElementsByTagName("li");
	for(var i=0;i<spans.length;i++){
		spans[i].setAttribute("index", i);
		//排他思想
		spans[i].οnclick=function(){
			for(var i=0;i<spans.length;i++){
				//removeAttribute() 方法删除指定的属性。
				 spans[i].removeAttribute("class");
			}
			//setAttribute(string name, string value):增加一个指定名称和值的新属性,或者把一个现有的属性设定为指定的值。
			 this.setAttribute("class", "active");

			 for(var i=0;i<lis.length;i++){
			 	lis[i].removeAttribute("class");
			 }
			  var index = this.getAttribute("index");
            //lis[index].className = "current";
            lis[index].setAttribute("class", "current");
		}
	}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值