原因不是这里。
backgroundColor和background在改变背景色是没有区别的

解决方案 »

  1.   


    <html> 
    <head> 
      <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> 
      <title>test</title> 
    </head> 
    <body> 
    <script language="javascript">  
    window.onload = function()
    {
    for(var i=1;i<4;i++)
    document.getElementById("tr"+i).onclick = truncolor;
    }
    function truncolor() 

    var tr=document.getElementById("trname");
    tr.style.background="#ffffff"; 
    this.style.background='#ff0000';
    tr.value = thid.id;

    </script> 
    <table width=500> 
    <tr><td><input type='hidden' name='trname' value='tr1'></td></tr> 
    <tr id=tr1 ><td>1fgdfsfsf</td></tr> 
    <tr id=tr2 ><td>2jhhddsda</td></tr> 
    <tr id=tr3 ><td>3aadfrrmx</td></tr> 
    </table> 
    </body> 
    </html>
      

  2.   

    <script language="javascript"> 
    <!-- 
    function turncolor(e) 

    for(var i=1; i<document.getElementsByTagName("table")[0].getElementsByTagName("tr").length;i++)
    {document.getElementsByTagName("table")[0].getElementsByTagName("tr")[i].style.background="ffffff"}
    e.style.background ="ff0000"

    --> 
    </script> 
    <table width=500  border="1"> 
    <tr> <td> <input type='hidden' name='trname' value='tr1'> </td> </tr> <tr Onclick="turncolor(this)" style="background:#ff0000"> <td>1fgdfsfsf </td> </tr> 
    <tr Onclick="turncolor(this)"  style="background:#ffffff"> <td>2jhhddsda </td> </tr> 
    <tr Onclick="turncolor(this)" style="background:#ffffff"> <td>3aadfrrmx </td> </tr> 
    </table> 
    这样的效果吗?
    起码你的函数名写错了  truncolor()  
      

  3.   

    当然啦,这里的写的代码只是一个table.其实在应用中,还有很多table的。所以以上代码不够好用。
    其他我用<input type='hidden' name='trname' value='tr1'>只是用来保存上次点击了哪一行的。
    其他在将上一次点击的行背景色变为fffff时,直接读取<input type='hidden' name='trname' value=''>这里的值即可的。
    所以,有没有更简单的代码呢?
      

  4.   

    <script language="javascript"> 
    <!-- 
    function turncolor(me) 

    var trID=document.getElementById("hid").value;
    document.getElementById(trID).style.background="#ffffff";
    document.getElementById("hid").value=me.id;
      me.style.background="#ff0000";

    </script> 
    <table width=500> 
    <tr><td><input type='hidden' id="hid" name='trname' value='tr1'></td></tr> <tr Onclick="turncolor(this);" id="tr1" ><td>1fgdfsfsf </td> </tr> 
    <tr Onclick="turncolor(this);" id="tr2" ><td>2jhhddsda </td> </tr> 
    <tr Onclick="turncolor(this);" id="tr3" ><td>3aadfrrmx </td> </tr> 
    </table> 
      

  5.   


    <script language="javascript"> 
    <!-- 
    function turncolor(me) 

    var trID=document.getElementById("hid").value;
    document.getElementById(trID).style.background="#ffffff";
    document.getElementById("hid").value=me.id;
      me.style.background="#ff0000";

    </script> 
    <table width=500> 
    <tr><td><input type='hidden' id="hid" name='trname' value='tr1'></td></tr> <tr Onclick="turncolor(this);" id="tr1" ><td>1fgdfsfsf </td> </tr> 
    <tr Onclick="turncolor(this);" id="tr2" ><td>2jhhddsda </td> </tr> 
    <tr Onclick="turncolor(this);" id="tr3" ><td>3aadfrrmx </td> </tr> 
    </table>