在经典论坛上一朋友问了这一问题,偶以前只试过表格隔行变色,li倒还真没有试过,不过感觉不难,于是就写了下面这段代码,实现了这个功能,自己收藏起来了.
<!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">
.style1{color:#f00;background:#eee}
.style2{color:#00f;background:#ccc}
</style>
<script type="text/javascript">
function chgListStyle(id){
var objId=document.getElementById(id);
if(objId){
for(var i=0;objId.childNodes[i]!=undefined;i++){
if(i%2==0)
objId.childNodes[i].className="style1";
else
objId.childNodes[i].className="style2";
}
}
}
</script>
</HEAD>
<BODY>
<ul id="a">
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
</ul>
<script type="text/javascript">
chgListStyle("a");
</script>
</BODY>
</HTML>