为什么select不能隐藏?

fukdown 2004-07-12 08:51:33
<script>
function s(t){
t.style.display="none";
}
</script>
<table border width=300>
<colgroup><col id=a></colgroup>
<colgroup><col id=b></colgroup>
<colgroup><col id=c></colgroup>
<tbody>
<tr>
<td onclick="s(a)">1</td>
<td onclick="s(b)">2</td>
<td onclick="s(c)">3</td>
</tr>
<tr>
<td><select><option>xxx</option></select></td>
<td>2</td>
<td>3</td>
</tr></</tbody>
</table>

其中如果<td>中的表单元素是其他的话可以隐藏,select元素则不行,为什么?
该如何实现这样的功能?
...全文
224 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
meizz 2004-07-12
  • 打赏
  • 举报
回复
这个可能是用 COL 的一个BUG吧, 用另外一种方法来实现:
<script>
function s(e)
{
var index = e.cellIndex;
var table = e.parentElement.parentElement.parentElement;
for(var i=0; i<table.rows.length; i++)
{
table.rows[i].cells[index].style.display = "none";
}
}
</script>
<table border width=300>
<colgroup>
<col id=a>
<col id=b>
<col id=c>
</colgroup>
<tbody>
<tr>
<td onclick="s(this)">1</td>
<td onclick="s(this)">2</td>
<td onclick="s(this)">3</td>
</tr>
<tr>
<td><select><option>xxx</option></select></td>
<td>2</td>
<td>3</td>
</tr>
</tbody>
</table>
hbzyduwu 2004-07-12
  • 打赏
  • 举报
回复
<script>
function s(){
document.all.t.style.display="none";
}
</script>
<td>
<select name="t">
<option>xxx</option>
</select>
<input type=button onclick=s() value="hidden">
</td>
guihengzhang 2004-07-12
  • 打赏
  • 举报
回复
input 也可以hidden的
好像只有select不能,要不你就先判断看td中是什么。
如果不是select就直接hidden,否则要获取该元素再hidden
zwhe 2004-07-12
  • 打赏
  • 举报
回复
event.srcElement.style.display="none";

87,916

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧