js实现隔行换色及其鼠标滑过变色

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>鼠标换色及鼠标滑过变色</title>
<style>
body{ font-size:12px; line-height:21px; color:#3e352f;}
ul{ width:200px; list-style:none;}
.one{ background-color:#f00;}
.two{ background-color:#dddabf;}
.one.three{ background:#fff;}
.two.three{ background:#000;}
</style>
</head>
<body>
 <ul>
  <li>1.假字以数十字为基础假字数…</li>
  <li>2.假字以数十字为基础假字数…</li>
  <li>3.假字以数十字为基础假字数…</li>
  <li>4.假字以数十字为基础假字数…</li>
  <li>5.假字以数十字为基础假字数…</li>
 </ul>
 <div id='aa'>增加className</div>
<script>
function set(){
var liNode=document.getElementsByTagName('li');
for(var i=0;i<liNode.length;i++){
    if(liNode[i].nodeType=='1'){
        if(i%2==0){
            liNode[i].className='one';
            liNode[i].onmouseout=function(){
                this.className='one';
            }
        }else{
            liNode[i].className='two';
            liNode[i].onmouseout=function(){
                this.className='two';
            }
        }
        liNode[i].onmouseover=function(){
            this.className='three';
        }


    }
}
}
addClass('aa','you')
//li aa
function addClass(element,value){
    var a=document.getElementById(element);
    var b=a.className;
    if(!b){
        a.className=value;
    }else{
        a.className=b +' '+ value;
    }
    console.log(a.className);
    
}
onload=set;
</script>
</body>
</html> 

 

转载于:https://www.cnblogs.com/positive/p/3656684.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值