do not use numbers as id, but try<table><tr>
<td width="30" height="30" id=2230>hello;</td>
 <td width="30" height="30" id=2330>world</td>
</tr>
</table>
<script>
function setcolor(obj,color)
{
  obj.bgColor = color;
}setcolor(document.all('<%=h%>'),'<%=states%>');
</script>

解决方案 »

  1.   

    我已经把id改为:t2230,t2330
    但是运行的时候它提示说:null不是对象
    那2个td设了颜色,但不是传递过去的那个颜色,是黑色!
      

  2.   

    1. try the color "red"
    2. and if possible, put the code in onload event handler, like this:<% h="t2230"
       states = "red"
    %>
    <body onload="
    setcolor(document.all('<%=h%>'),'<%=states%>');">
    <table><tr>
    <td width="30" height="30" id=t2230>hello;</td>
     <td width="30" height="30" id=t2330>world</td>
    </tr>
    </table>
    <script>
    function setcolor(obj,color)
    {
      obj.bgColor = color;
    }//setcolor(document.all('<%=h%>'),'<%=states%>');
    </script>
    </body>
      

  3.   

    颜色可以了,也可以在相应的td设置相应的颜色
    但是还是出现"null不是对象"
      

  4.   

    make sure those "id"'s exist