我想一片相关的控件都变成blue,但是这样错误了,如果把str改成固定的值,就能成功 
for(var icount=0 ; icount <= x ; icount++ ) 
    { var str =(""+icount+","+y+"").toString(); 
document.getElementById(str).style.background="blue"; 
  } 
我的问题什么原因,怎么解决<td    width=4pt align="center" onclick="ChangeColor(this)" onmouseover="overtMouse(this)"  onmouseout="outMouse(this)" > <FONT style="BACKGROUND-COLOR: green"  id='+col+','+row+'  >'+"  "+' </FONT> </td> 
我调用的对象

解决方案 »

  1.   

    str = icount+","+y 试试
      

  2.   

    var str =(""+icount+","+y+"").toString();
    alert(str);//看看是不是你要的值
      

  3.   

    var str =(""+icount+","+y+"").toString(); 
    alert(str);看看和你的ID是否一样
      

  4.   

    如果var str =(""+1+","+y+"")就能成功 而把1变成变量icount就错误了,就是不让我动态
      

  5.   

    icount可是从0开始
    var str =(""+0+","+y+"")能成功吗?
      

  6.   

      id='+col+','+row+'  ??
    -------------
    test(IE6-OK)<body><table border="1" width="100%" cellspacing="0" cellpadding="0">
    <tr>
    <td    width=4pt align="center" onclick="ChangeColor(this)" onmouseover="overtMouse(this)"  onmouseout="outMouse(this)" > <FONT style="BACKGROUND-COLOR: green;color:#fff"  id=0,1  >  </FONT> </td> 
    <td    width=4pt align="center" onclick="ChangeColor(this)" onmouseover="overtMouse(this)"  onmouseout="outMouse(this)" > <FONT style="BACKGROUND-COLOR: green;color:#fff"  id=1,1  >  </FONT> </td> 
    <td    width=4pt align="center" onclick="ChangeColor(this)" onmouseover="overtMouse(this)"  onmouseout="outMouse(this)" > <FONT style="BACKGROUND-COLOR: green;color:#fff"  id=2,1  >  </FONT> </td> 
    </tr>
    </table>
    <script language="javascript">
    <!--
    var x=2,y=1
    for(var icount=0 ; icount <= x ; icount++ ) { 
    var str =(""+icount+","+y+"").toString(); 
    document.getElementById(str).style.background="blue"; 

    //-->
    </script></body>