主页教程js教程查看内容

js实现隔行改变颜色

2015-12-03 | 发布者: 72cms.com | 栏目:js教程

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>js实现隔行改变颜色</title>
 
</head>
<body>
<div class="">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
<script>
var aLi = document.getElementsByTagName('li');
for(var i=0;i<aLi.length;i++){
if(i%2==0){
           aLi[i].style.background='#ccc';
}else{
 aLi[i].style.background='';
}
}
</script>
 
</body>
</html>