<table width="100%" border="1">
<tr onclick="this.style.backgroundColor='red'">
<td>
asd</td>
</tr>
<tr onclick="this.style.backgroundColor='red'">
<td>
asd</td>
</tr>
<tr onclick="this.style.backgroundColor='red'">
<td>
asd</td>
</tr>
</table>

解决方案 »

  1.   

    <script>
    function f1(obj)
    {
    obj.style.backgroundColor="red";
    }</script>
    <table>
    <tr onclick=f1(this)><td>ssssssss</td><td>ddddddddddd</td></tr>
    <tr onclick=f1(this)> <td>ssssssss</td><td>ddddddddddd</td></tr>
    </table>
      

  2.   

    <script>
    function ChgColor(s)
    {
    if(s.style.backgroundColor!='')
    {
    s.style.backgroundColor=''
    }else
    {
    s.style.backgroundColor='red'
    }
    }
    </script>
    <table width="100%" border="1">
    <tr onClick="ChgColor(this)">
    <td>点击</td>
    </tr>
    </table>
      

  3.   

    <table width="100%" border="1">
    <tr style="background-color:blue" onclick="for(var i=0;i<this.parentNode.childNodes.length;i++){this.parentNode.childNodes[i].style.backgroundColor='blue'}this.style.backgroundColor='red'">
    <td>
    asd</td>
    </tr>
    <tr style="background-color:blue" onclick="for(var i=0;i<this.parentNode.childNodes.length;i++){this.parentNode.childNodes[i].style.backgroundColor='blue'}this.style.backgroundColor='red'">
    <td>
    asd</td>
    </tr>
    <tr style="background-color:blue" onclick="for(var i=0;i<this.parentNode.childNodes.length;i++){this.parentNode.childNodes[i].style.backgroundColor='blue'}this.style.backgroundColor='red'">
    <td>
    asd</td>
    </tr>
    </table>
      

  4.   

    <SCRIPT LANGUAGE="JavaScript">
    function setRow(trid)
     {
      tr = document.createElement("TR");
      td = document.createElement("TD");
      td2 = document.createElement("TD");
      text= document.createTextNode("fff");
      text2= document.createTextNode("kkkkk");
      td.insertBefore(text,null);
      td2.insertBefore(text2,null);
      tr.insertBefore(td, null);
      tr.insertBefore(td2, null); 
      tr.onclick=function()
       {
         var tdobj=document.all.t1.childNodes[0].childNodes;
        for(var i=0;i<tdobj.length;i++)
           {
                 tdobj[i].style.backgroundColor="";
               }
        this.style.backgroundColor="red";
      
      }
      tbody1.appendChild(tr); 
       
    }</SCRIPT><INPUT TYPE="button" onclick="setRow('tr1')" value="添加" ID=Button1>
    <TABLE id="t1" border=1 width=80>
    <TBODY id="tbody1">
    </tbody>
    </TABLE>