解决方案 »

  1.   

    <table id="t1">
    <tr><td>1</td><td>3</td></tr>
    <tr><td>2</td><td>4</td></tr>
    </table>
    <script>
    document.getElementById("t1").rows[0].style.backGround = "red";
    </script>
      

  2.   

    刚才的代码有一个笔误 backGround -> backgroundColor <head>
    <script>
    function init(){
    document.getElementById("t1").rows[0].cells[0].style.backgroundColor = "red";}
    </script>
    </head>
    <body onload="init()">
    <table id="t1">
    <tr><td>1</td><td>3</td></tr>
    <tr><td>2</td><td>4</td></tr>
    </table>
    </body>
      

  3.   

    非常感谢您的回答,目前我是这么处理的var tr = document.createElement("tr");tr.setAttribute("style", "background-color:"+(i%2 == 0 ? "#FFFFFF" : "#FFFFF0")+";");i是循环的键值。不知是否知道这样为什么IE7下有问题。
      

  4.   

    已解决,是通过tr.style.backgroundColor = (i%2 == 0 ? "#FFFFFF" : "#FFFFF0");来解决的,setAttribute貌似在IE7版本以下就不那么好使。
      

  5.   

    u can use DomElement.style.cssText to set the style for ie 7.