id不要重复 如果你是想隐藏table里的所有td 那你可以设置table 的id然后控制他就可以了
<table id=tbl>
<tr>
<td></td>
<td></td>
...
</tr>
<table>function HiddenEle(e)
{
e.style.display="none";}
<table id=tbl>
<tr>
<td></td>
<td></td>
...
</tr>
<table>function HiddenEle(e)
{
e.style.display="none";}
按你说的,id不重复,第一行的<td>可以显示隐藏,但以后的都不行,我要一部分<td>显示/隐藏,所以用一个table不行
假设为showidfunction HiddenEle()
{
var e = document.all.getElementsByName("shiwid");
for (i=0;i<e.length;i++)
e[i].style.display="none";
}
假设为showidfunction HiddenEle()
{
var e = document.all.getElementsByName("showid");
for (i=0;i<e.length;i++)
e[i].style.display="none";
}
如果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>