js、jq、点击改变字体颜色背景色

 

css:

.zhuantai{width: 90%;height: 70px;border-top: 1px solid #bdbcbc; border-bottom: 1px solid #bdbcbc; margin: 10px auto;}

.yinye{display: inline-block;height: 70px;width: 30%;float: left;color: #ff4949; font-size: 25px;line-height: 70px;text-align: center;}

.xiuxi{display: inline-block;height: 70px;width: 30%;float: right;font-size: 25px;line-height: 70px;text-align: center;}

html:

<div class="zhuantai" id="zt">
<span class="yinye">营业中</span>
<span class="xiuxi">休息中</span>
</div>

js:

<script type="text/javascript">

    window.οnlοad=function(){
        var lis=document.getElementById("zt").getElementsByTagName("span");
        for(var i=0;i<lis.length;i++){
            lis[i].setAttribute("index",i);
            lis[i].οnclick=function(){
                for(var i=0;i<lis.length;i++){
                    if(this.getAttribute("index")==i){
                        lis[i].style.color="#ff4949";
                        lis[i].style.background="black";
                    }else{
                        lis[i].style.color="#060606";
                        lis[i].style.background="green";
                    }
                }
            }
        }
    }
</script>

<style>
ul li{
	list-style: none;
}
li{
	width: 60px;
	height: 30px;
	color: #000;
	background: #fff;
}
.on{
	background: red;
	color: #fff;
}
</style>
</head>
<body>
	<div id="show_quan">  
    <ul>  
    <li class="on">1</li>  
    <li>2</li>  
    <li>3</li>  
    </ul>  
</div> 
<script type="text/javascript">  
    $('#show_quan li').each(function(i,v){//遍历加                          
        $(v).click(function(){   
            $(this).addClass('on').siblings().removeClass('on'); 
            });  
       });  
</script>   
</body>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

林中明月间。

分享共赢。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值