电脑技术学习

javascript使li元素隔行变色代码--兼容性好

dn001

<style type="text/css">
<!--
.li01 { background:#FFF; }
.li02 { background:#eeeeee; }
-->
</style>
<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").childNodes;
for (i=0;i<objName.length;i++) {
(i%2==0)?(objName[i].className = "li01"):(objName[i].className = "li02");
}
</script>