网络编程
位置:首页>> 网络编程>> 网页设计>> css学习笔记:表格隔行点击变色

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

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

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

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

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

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

● 在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>


全部源码:


 

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com