java中隔行变色

<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=""+this.innerHTML+"
";
      };
    }
}
script>
head>
<table id="table1" width="300" border="1" cellpadding="0" cellspacing="0" align="center" >
 
<tr>
   
<td>Line1Line1Line1Line1td>
 
tr>
 
<tr>
   
<td>Line2Line2Line2Line2td>
 
tr>
 
<tr>
   
<td>Line3Line3Line3Line3td>
 
tr>
 
<tr>
   
<td>Line4Line4Line4Line4td>
 
tr>
 
<tr>
   
<td>Line5Line5Line5Line5td>
 
tr>
table>

你可能感兴趣的:(java中隔行变色)