document.getElementById("td"+i).background = "url(images/son_menu2.gif)"; 

解决方案 »

  1.   

    应该是document.getElementById("td"+i).style.backgroundImage="url(images/son_menu2.gif)"; 
      

  2.   

    document.getElementById("td"+i).style.backgroundImage
      

  3.   

    html:
    <td width="551" height="270" background="pic/index_r2_c4.jpg" id="centerPic">&nbsp;</td>js:
    centerPic.background='pic/back.jpg';
      

  4.   

    试过了,这样写就可以。
    function changebj(num) 
    {  
      var eName = "td" + num;
      document.all(eName).background="images/son_menu2.gif"; 
      

  5.   

    for (i=0;i <tdlist.length;i++) 
      { 
      if (i==num) 
      { 
      document.getElementById("td"+i).backgroundimage="url(images/son_menu2.gif)"; 
      } 
    else 
      { 
        document.getElementById("td"+i).backgroundimage="url(images/son_menu.gif)"; 
      } 
    ------------------------------------------------------------------------------------
    LZ,你这里i从0开始,但是你的td编号从1开始
    也就是说并不存在id未"td0"的Element
    所以你执行到document.getElementById("td"+0)的时候获取不到对象,JS出错
    那么这个方法就执行不下去了正确的写法
    function changebj(num) 

    var obj=document.getElementById("changebj"); 
    var tdlist=obj.getElementsByTagName("td"); 
    for (i=0;i <tdlist.length;i++) 
      { 
      if (tdlist[i].id=="td"+num) 
      { 
      tdlist[i].style.backgroundImage="url(images/son_menu2.gif)"; 
      } 
    else 
      { 
        tdlist[i].style.backgroundImage="url(images/son_menu.gif)"; 
      } 


    I要大写也可以
    function changebj(num) 

    var obj=document.getElementById("changebj"); 
    var tdlist=obj.getElementsByTagName("td"); 
    for (i=0;i < tdlist.length;i++) 
      { 
      if (i+1==num) 
      { 
      document.getElementById("td"+(i+1)).style.backgroundImage="url(images/son_menu2.gif)"; 
      } 
    else 
      { 
        document.getElementById("td"+(i+1)).style.backgroundImage="url(images/son_menu.gif)"; 
      }