既然能动态生成id,就能得到这个id
然后使用document.getElementById("tr的id").style.backgroundColor="red"

解决方案 »

  1.   

    <script>
    function cc(a){
     a.style.backgroundColor="red"
    }
    </script>
    </HEAD>
    <BODY>
    <TABLE id="table1" border="1">
    <TR onclick="cc(this)">
    <TD>aaaa</TD>
    <TD><a href="#" >111111</a></TD>
    </TR>
    <TR onclick="cc(this)">
    <TD>bbbbb</TD>
    <TD><a href="#" onclick="InsertRow();">22222</a></TD>
    </TR>
    <TR onclick="cc(this)">
    <TD>ccccc</TD>
    <TD><a href="#" onclick="InsertRow();">33333</a></TD>
    </TR>
    <TR onclick="cc(this)">
    <TD>dddddd</TD>
    <TD><a href="#" onclick="InsertRow();">444444</a></TD>
    </TR>
    </TABLE>
      

  2.   

    <script language="javascript">
    function trfocus(){this.style.background="#CCCCCC";}
    function trblur(){this.style.background="";}
    function window.onload()
    {
    var trs = document.getElementByTagName("tr");
    for(var i=0;i<trs.length;i++)
    {
    trs[i].onmouseover = trfocus;
    trs[i].onmouseout = trblur;
    }
    }
    </script>
      

  3.   

    //gzdiablo使用的getElementByTagName类,不知道为什么,我使用这个的时候总是提示
    对象不支持该方法,所以我不喜欢:)
    <html>
    <head>
    <title>枚举字符串</title><body><table border=1  id="tb1">
    <tr id="tr1"><td>&nbsp;aaaaa</td><td>&nbsp;aaaaa</td></tr>
    <tr id="tr2"><td>&nbsp;bbbbbb</td><td>&nbsp;aaaaa</td></tr>
    <tr id="tr3"><td>&nbsp;aaaaa</td><td>&nbsp;aaaaa</td></tr>
    <tr id="tr4"><td>&nbsp;bbbbbb</td><td>&nbsp;aaaaa</td></tr>
    </table>
    <script language="javascript">
    function trfocus(){this.style.background="#CCCCCC";}
    function trblur(){this.style.background="";}
    function window.onload()
    {
    var trs = document.getElementById("tb1");
    if(trs.lastChild.hasChildNodes()){
    var s=trs.lastChild.childNodes.length;  for(var i=0;i<s;i++){
       trs.lastChild.childNodes[i].onmouseover=trfocus;
       trs.lastChild.childNodes[i].onmouseout=trblur;
      }
     }
    }
    </script>
    </body>
    </html>
      

  4.   

    谢谢大家
    尤其谢谢gzdiablo
    getElementByTagName 应该写成 getElementsByTagName谢谢你们~~
    小弟的分不多,
    但是真的谢谢
    问题解决了