id不要重复 如果你是想隐藏table里的所有td 那你可以设置table 的id然后控制他就可以了
<table id=tbl>
<tr>
<td></td>
<td></td>
...
</tr>
<table>function HiddenEle(e)
{
e.style.display="none";}

解决方案 »

  1.   

    to vjlin(伟杰)(简单快乐) :
    按你说的,id不重复,第一行的<td>可以显示隐藏,但以后的都不行,我要一部分<td>显示/隐藏,所以用一个table不行
      

  2.   

    ID重复的话,document.all.showhidtd拿到的是数组,应该document.all.showhidtd[i]带下标访问。
      

  3.   

    将TD的NAME设成一样的
    假设为showidfunction HiddenEle()
    {
             var e = document.all.getElementsByName("shiwid");
             for (i=0;i<e.length;i++)
        e[i].style.display="none";
    }
      

  4.   

    将TD的NAME设成一样的
    假设为showidfunction HiddenEle()
    {
             var e = document.all.getElementsByName("showid");
             for (i=0;i<e.length;i++)
        e[i].style.display="none";
    }
      

  5.   

    这样就行了.
    如果id有重复的话,就不能直接e.style.display="none";
    要用数组来访问.
    所以,你要完善一下,你的函数.
    加入 e.length 来判断,是否为有数组.
    如果是数组,再循环每个元素..<table>
    <tr><td id="showhidtd">灰豆宝宝.net</td></tr>
    <tr><td id="showhidtd">灰豆宝宝.net</td></tr>
    </table>
    <input type=button onclick="HiddenEle(document.all('showhidtd'))" value="get">
    <script>
    function HiddenEle(e)
    {
        if(e.length)
    {
        for(var i=0;i<e.length;i++)
        e[i].style.display="none";
    }
    else
    {
        e.style.display="none";
    }
    }
    </script>
    </body>