table中行的颜色变化

来源:互联网 发布:ubunto怎么下载软件 编辑:程序博客网 时间:2024/04/29 18:43

 1.新建一个table

123123123123123123123123123123123123

2.使用js

<script type="text/javascript">
      //senfe(表格名称,奇数行颜色,偶数行颜色,鼠标划过后颜色)
        function senfe(o,a,b,c){
             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(){
                            this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;
              }
              t[i].onmouseover=function(){
             this.style.backgroundColor=c;
              }
              t[i].onmouseout=function(){
              this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;
              }
             }
        }
     </script>

3.调用js

<script type="text/javascript">
        senfe("table1","#FF0000","#000000","#6633FF");
   </script>

4.效果展示如 Demo