css学习笔记:表格隔行点击变色

来源:好好的好好 时间:2009-04-30 13:15:00 

我们经常会用到表格数据,在做表格的时候,一般都喜欢隔行变色,使表格表现数据的时候非常的清晰。

如图,我设计的一个表格表现的样式:

在网上找到一个非常好的表格隔行点击变色效果的制作方法,我认为这个作法是比较实用的。

● 在head和body区分别加上JS:

<script language="javascript"><!--
function senfe(o,a,b,c,d){
 var t=document.getElementById(o).getElementsByTagName("tr");
 for(var i=0;i<t.length;i++){
  t[i].style.backgroundColor=(t[i].sectionRowIndex%2==0)?a:b;
  t[i].onclick=function(){
   if(this.x!="1"){
    this.x="1";//本来打算直接用背景色判断,FF获取到的背景是RGB值,不好判断
    this.style.backgroundColor=d;
   }else{
    this.x="0";
    this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;
   }
  }
  t[i].onmouseover=function(){
   if(this.x!="1")this.style.backgroundColor=c;
  }
  t[i].onmouseout=function(){
   if(this.x!="1")this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;
  }
 }
}
--></script>

<script language="javascript"><!--
//changecolor("表格名称","奇数行背景","偶数行背景","鼠标经过背景","点击后背景");
senfe("changecolor","#f8fbfc","#e5f1f4","#ecfbd4","#bce774");
--></script>


● 给table赋一个ID:changecolor

<table class="warp_table" id="changecolor">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>


全部源码:


 

标签:css,表格,隔行变色,table
0
投稿

猜你喜欢

  • XML编程实例:用ASP+XML打造留言本

    2008-05-04 13:37:00
  • getWindow与isWindow

    2009-12-28 13:12:00
  • 在MySQL中使用更新日志文件

    2009-02-26 16:22:00
  • 账户名和密码漏输或误输的文字提示

    2009-06-24 14:28:00
  • 设计师和美工

    2008-10-27 13:43:00
  • JS复制特定内容到粘贴板

    2011-04-02 11:09:00
  • 如何解决客户机页面刷新时连接不上数据库问题?

    2009-12-16 18:24:00
  • asp如何修改WINNT的登录密码?

    2010-06-10 17:06:00
  • thinkphp5实用入门进阶知识点和各种常用功能代码汇总

    2023-05-25 02:48:34
  • 10个美观实用的 jQuery/Mootools 日历插件

    2009-09-17 13:03:00
  • 网页制作,改变你的思维方式

    2007-09-29 13:12:00
  • Javascript编写Asp时需要注意的一些地方

    2008-04-06 14:20:00
  • 创建IE各版本专属CSS方法

    2007-09-27 12:16:00
  • 各浏览器 CSS Hack 整理

    2008-01-17 10:54:00
  • 图标设计常犯的10种错误

    2008-03-06 13:40:00
  • MYSQL教程:MYSQL字符集支持

    2009-02-27 15:55:00
  • SQL Server 2005恢复Master库

    2011-05-16 13:11:00
  • 某一公司的ASP面试题

    2011-09-15 20:50:20
  • opera img onload重复执行

    2008-01-17 12:01:00
  • 滚动条样式的css代码介绍

    2008-10-21 10:56:00
  • asp之家 网络编程 m.aspxhome.com