标签:
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>
标签:
原文地址:http://www.cnblogs.com/bravolove/p/5982718.html