交互设计中心-72色

交互设计中心 | 用户体验 | 优化

不用js实现带序号的表格隔行换色的效果

2009年1月13日 | 分类:DIV+CSS | 评论:1 | 引用:0 | | Tags:序号  隔行换色  
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>不用js实现带序号的表格隔行换色的效果-/title>
<style>   
.test{   
border:1px solid #000;   
color:#333;   
font:12px;   
}   
.test ol li{   
padding-left:5px;   
background-color:expression(this.sourceIndex%2? '#ff0':'#00f');   
}   
</style>
</head><body><div class="test">  
<ol>  
<li>鼠标特效</li>  
<li>页面特效</li>  
<li>背景特效</li>  
<li>导航菜单</li>  
<li>状态栏类</li>  
<li>文本特效</li>  
<li>链接特效</li>  
<li>图形特效</li>  
<li>窗口特效</li>  
<li>按钮特效</li>  
<li>亦 时间日期</li>  
<li>CSS相关</li>  
<li>代码生成</li>  
<li>计数转换</li>  
<li>游戏娱乐</li>  
<li>系统相关</li>  
<li>黑客性质</li>  
<li> 综合特效</li>  
</ol>  
</div>
</body>
</html>
 

<meta content="text/html; charset=gb2312" http-equiv="Content-Type" /><style type="text/css">    .test{    border:1px solid #000;    color:#333;    font:12px;    }    .test ol li{    padding-left:5px;    background-color:expression(this.sourceIndex%2? '#ff0':'#00f');    }    </style></p><div class="test"><ol>    <li style="background-color: #00f">鼠标特效</li>    <li style="background-color: #ff0">页面特效</li>    <li style="background-color: #00f">背景特效</li>    <li style="background-color: #ff0">导航菜单</li>    <li style="background-color: #00f">状态栏类</li>    <li style="background-color: #ff0">文本特效</li>    <li style="background-color: #00f">链接特效</li>    <li style="background-color: #ff0">图形特效</li>    <li style="background-color: #00f">窗口特效</li>    <li style="background-color: #ff0">按钮特效</li>    <li style="background-color: #00f">亦 时间日期</li>    <li style="background-color: #ff0">CSS相关</li>    <li style="background-color: #00f">代码生成</li>    <li style="background-color: #ff0">计数转换</li>    <li style="background-color: #00f">游戏娱乐</li>    <li style="background-color: #ff0">系统相关</li>    <li style="background-color: #00f">黑客性质</li>    <li style="background-color: #ff0">综合特效</li></ol></div><p>

-------------------------------------------------------------------
下面这个是用js的写法

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>LI标签隔行换色效果</title>
</head><body>
<style>
.mytable {border-collapse:collapse;border:solid #6AA70B;border-width:0px 0 0 0px;width:50%;}
.mytable ul li {padding-top:5px;text-indent:2em;list-style:none;background:url(../images/new.gif) 3px 50% no-repeat;border-bottom:#6AA70B 1px dotted ;font-family: "Verdana,宋体";font-size: 12px;color:#008000;text-align:left;height:25px;}
.mytable ul li.t1 {background-color:#EFFEDD;}/* 第一行的背景色 */
.mytable ul li.t2{background-color:#ffffff;}/* 第二行的背景色 */
.mytable ul li.t3 {background-color:#D2FCA0;}/* 鼠标经过时的背景色 */
</style>
<body style=margin:0;><br><br><br>
<div align="center">
<div class=mytable id=tab>
<ul>
    <li><a href="#">这个是第1行的文字,大家看清楚了</a></li>
<li><a href="#">这个是第2行的文字,大家看清楚了</a></li>
<li><a href="#">这个是第3行的文字,大家看清楚了</a></li>
<li><a href="#">这个是第4行的文字,大家看清楚了</a></li>
<li><a href="#">这个是第5行的文字,大家看清楚了</a></li>
<li><a href="#">这个是第6行的文字,大家看清楚了</a></li>
<li><a href="#">这个是第7行的文字,大家看清楚了</a></li>
<li><a href="#">这个是第8行的文字,大家看清楚了</a></li>
<li><a href="#">这个是第9行的文字,大家看清楚了</a></li>
</ul></div><script type="text/javascript">
<!--
var Ptr=document.getElementById("tab").getElementsByTagName("li");
function $() {
      for (i=1;i<Ptr.length+1;i++) {
      Ptr[i-1].className = (i%2>0)?"t1":"t2";
      }
}
window.onload=$;
for(var i=0;i<Ptr.length;i++) {
      Ptr[i].onmouseover=function(){
      this.tmpClass=this.className;
      this.className = "t3";   
      };
      Ptr[i].onmouseout=function(){
      this.className=this.tmpClass;
      };
}
//-->
</script>
</body>
</html>

Share
« 站长版《伤心太平洋》-《伤心的站长》超酷极眩的苹果机(MAC)OS系统导航条(CSS+JS实现) »
  1. biggates头像
    biggates 2009-1-13 21:57:37 1

    其实CSS表达式会影响速度的,不是很推荐使用。
    使用的时候看实际情况吧。

    chia 于 2009-1-14 8:54:34 回复
    恩 这倒是, 不过各有利弊吧




◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。