java中隔行变色

来源:互联网 发布:功能测试使用的软件 编辑:程序博客网 时间:2024/04/29 16:31

<style>
table tr
{
  background-color
:expression(this.rowIndex%2==0 ? "#ffffff" : "#c0c0c0");
}
</style>
<script>
var oldTd,oldTdText;
window.onload
=function(){
 
var table1 = document.getElementById("table1");
 
var rows = table1.rows;
 
for(i=0; i<rows.length; i++)
    {
      rows[i].cells[
0].onmouseover=function(){
       
if(oldTd)
        {
          oldTd.innerHTML
=oldTdText;
        }
        oldTd
=this;
        oldTdText
=this.innerHTML;
       
this.innerHTML="<font style='background-color:red'>"+this.innerHTML+"</font>";
      };
    }
}
</script>
</head>
<table id="table1" width="300" border="1" cellpadding="0" cellspacing="0" align="center" >
 
<tr>
   
<td>Line1Line1Line1Line1</td>
 
</tr>
 
<tr>
   
<td>Line2Line2Line2Line2</td>
 
</tr>
 
<tr>
   
<td>Line3Line3Line3Line3</td>
 
</tr>
 
<tr>
   
<td>Line4Line4Line4Line4</td>
 
</tr>
 
<tr>
   
<td>Line5Line5Line5Line5</td>
 
</tr>
</table>