以前的做法是偶数行时给li加一个class,方法当然不可取,如果后台读取再加class就很麻烦了,看看这个效果:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<style type="text/css">
<!--
.li01 { background:#FFF; }
.li02 { background:#eeeeee; }
-->
</style>
</HEAD><BODY>
<div ><ul id="list01">
<li class="title"><a href="#">title</a></li>
<li><a href="#">111</a></li>
<li><a href="#">222</a></li>
<li><a href="#">333</a></li>
<li><a href="#">444</a></li>
<li><a href="#">555</a></li>
<li><a href="#">666</a></li>
</ul></div>
<script Language="Javascript">
objName=document.getElementById("list01").getElementsByTagName("li")for (i=0;i<objName.length;i++) {
(i%2==0)?(objName(i).className = "li01"):(objName(i).className = "li02");
}
</script>
</BODY>
</HTML>
效果可以~