利用JavaScript的%做隔行换色

<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
    li {
        list-style-type: none;
        width: 300px;
        height: 30px;
    }
</style>
</head>

<body>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<script type="text/javascript">
    var oli=document.getElementsByTagName('li');
    for(var i=0;i<oli.length;i++) //i++后面不要加分号
        {
            if(i%2==0)
                {
                    oli[i].style.background='#F17B7D';
                }
            else
                {
                    oli[i].style.background='#EDB461';
                }
        }
</script>
</body>
</html>

查看原文

posted @ 2017-11-24 20:23  绿林豪士  阅读(326)  评论(0编辑  收藏  举报