首页 > Web开发 > 详细

js - 03课-01 隔行变色, 鼠标移入移出变色

时间:2016-10-21 00:35:44      阅读:248      评论:0      收藏:0      [点我收藏+]

1. 效果图

技术分享

2. 源码

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        li { height:24px; margin-bottom:3px; list-style:none; }
    </style>
</head>
<body>
<ul id="ul1">
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
</ul>

<script>
    window.onload = function(){
        var aLi = document.getElementsByTagName(‘li‘)
        var arrColor = [‘red‘,‘yellow‘,‘blue‘]
        for(var i=0; i < aLi.length; i++){
            aLi[i].index = i;
            aLi[i].style.background = arrColor[i % arrColor.length]
            aLi[i].onmouseover = function(){
                this.style.background = ‘gray‘;
            }
            aLi[i].onmouseout = function(){
                this.style.background = arrColor[this.index % arrColor.length]
            }
        }
    }
</script>
</body>
</html>

 

js - 03课-01 隔行变色, 鼠标移入移出变色

原文:http://www.cnblogs.com/bravolove/p/5982718.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!