当前位置:沸点梦工场 > 网页设计教程 > JavaScript教程 > 浏览文章

用JavaScript使列表LI隔行换色

本站原创 2007年08月24日 【字体:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style>
body{
 font-size:12px;
 line-height:21px;
 color:#3E352F;
}
ul{
 width:200px;
 list-style:none;
}
.one{
 background:#CDC194;
}
.two{
 background:#DDDABF;
}
 
</style>
<script>
function set(){
var obj=document.getElementsByTagName("li");
var num=obj.length
for(var i=0;i<num;i++){
if(i%2==0){
obj[i].className="one";
}else{
obj[i].className="two";
}
}
}
</script>
</head>
<body onload="set()">
 <ul>
  <li>1.假字以数十字为基础假字数…</li>
  <li>2.假字以数十字为基础假字数…</li>
  <li>3.假字以数十字为基础假字数…</li>
  <li>4.假字以数十字为基础假字数…</li>
  <li>5.假字以数十字为基础假字数…</li>
 </ul>

</body>
</html>