<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
.EvenOrOddRow{
background-color: expression((this.sectionRowIndex%2)?'white':'#E0E0E0');
}</style>
<script>
var currentActiveRow;
function changeActiveRow(obj)
{
if(currentActiveRow) currentActiveRow.style.backgroundColor="";
currentActiveRow=obj;
currentActiveRow.style.backgroundColor="Red";
}</script>
</head>
<body>
<table width=100%>
<tr bgcolor=aaaaaa >
<td>Code</td><td>Name</td>
</tr>
<tr class="EvenOrOddRow" onclick="changeActiveRow(this);">
<td>001</td><td>zhangsan</td>
</tr>
<tr class="EvenOrOddRow" onclick="changeActiveRow(this);">
<td>001</td><td>zhangsan</td>
</tr>
<tr class="EvenOrOddRow" onclick="changeActiveRow(this);">
<td>001</td><td>zhangsan</td>
</tr>
<tr class="EvenOrOddRow" onclick="changeActiveRow(this);">
<td>001</td><td>zhangsan</td>
</tr></body>

解决方案 »

  1.   

    var curRow;   //全局行号
    var curRowId; //选中行的记录信息的ID
    var curColor;
    function selectRow(tr1){
    if(curRow)
    {
    curRow.bgColor=curColor;
    curColor=tr1.bgColor;
    tr1.bgColor="#FFE9B3";
    }else{
    curColor=tr1.bgColor;
    tr1.bgColor="#FFE9B3";
    }
    curRow=tr1;
    curRowId=tr1.id;
    }
    调用方法:<tr onclick="selectRow(this)"
      

  2.   

    colidx = 0;
    curRow.cells[colidx].bgcolor = "#######" use it , you can do it
      

  3.   

    改变 td 的 CSS 或 bgColor ~
      

  4.   

    <td valign="baseline" onmouseover="this.style.backgroundColor='#e7e7c7'" onMouseOut="this.style.backgroundColor='#f6f6f6'"> 给你一语最简单的,把td 换成tr 也可以
      

  5.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    </HEAD><BODY>
    <script language="javascript">
    function chcolor(obj,color)
    {
       for(var i=0;i<obj.parentElement.parentElement.parentElement.rows.length;i++)
       {
        obj.parentElement.parentElement.parentElement.rows[i].style.backgroundColor='';
       }
    var tdid=obj.parentElement.parentElement; //取得所在tr
    tdid.style.backgroundColor="CornflowerBlue";
    }
    </script><table border=1>
    <tr id="line1"><td width=100></td> <td><input type=button onclick="chcolor(this,'#0000FF')" value='点击变颜色'></td> </tr>
    <tr id="line2"><td width=100></td> <td><input type=button onclick="chcolor(this,'#FF0000')" value='点击变颜色'></td> </tr>
    <tr id="line3"><td width=100></td> <td><input type=button onclick="chcolor(this,'#00FF00')" value='点击变颜色'></td> </tr>
    </table>
    </BODY>
    </HTML>