[请问]怎样取得表格的某一列宽度的像素值?——解决问题立即结贴!

天地客人 2006-03-30 01:14:28
如类下表格:
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>这列宽度为:**</td>
<td>这列宽度为:**</td>
</tr>
</table>
没有指定列的宽度为决对值像素或%多少,完全根据浏览器的宽度决定!

请问:如何使用javascript获取此列的实际宽度像素?

如类似这样的算法:
<td>这列宽度为<script language=JAVASCRIPT>document.write(this.width);</script></td>
...全文
190 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xb8254 2006-03-30
  • 打赏
  • 举报
回复
gz
wangchine 2006-03-30
  • 打赏
  • 举报
回复
不错,做个记号
cvpc 2006-03-30
  • 打赏
  • 举报
回复
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td onclick="javascript:alert(this.offsetWidth);">这列宽度为:**</td>
<td onclick="javascript:alert(this.offsetWidth);">这列宽度为:**</td>
</tr>
</table>
孟子E章 2006-03-30
  • 打赏
  • 举报
回复
<table width="100%" border="0" cellpadding="0" cellspacing="0" id=t>
<tr>
<td>这列宽度为:**</td>
<td>这列宽度为:**</td>
</tr>
</table>

<input type=button onclick=GetIT()>
<script>
function GetIT()
{
o = document.getElementById("t")
alert(o.offsetWidth)
alert(o.rows[0].cells[0].offsetWidth)
alert(o.rows[0].cells[0].offsetWidth)
}
</script>

87,901

社区成员

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

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