有办法得到一个对象的属性列表吗?比如
中width,height...

alula 2001-12-06 09:22:23
这些属性在对象中是怎么保存的,有办法判断这个<tr>是否具有 width 属性呢?
...
...全文
99 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
karma 2001-12-07
  • 打赏
  • 举报
回复
<table id="tbl">
<tr><td>hello</td><td>world</td></tr>
<tr width='95%' height='20'><td>hello</td><td>world</td></tr>
<tr width='95%' height='20'><td>hello</td><td>world</td></tr>
</table>
<input type="button" value="show Att" onclick="showAtt()">

<script language="javascript">
function showAtt()
{
var row = document.all("tbl").rows[0]; //second row
var width = row.getAttribute("width");
var height = row.getAttribute("height");

if (width)
alert("we have a width attribute, its value:" + width);
else
alert("we don't have a width attribute");

if (height)
alert("we have a height attribute, its value::" + height);
else
alert("we don't have a height attribute");
}
</script>
y1g1y1 2001-12-07
  • 打赏
  • 举报
回复
查 MSDN 啊!
feijunjun 2001-12-07
  • 打赏
  • 举报
回复
<table>
<tr id=abc width=80 height=40 tt=200>
<td>tr中的tt是一个自定义属性</td>
</tr>
</table>
<script>
for(var e in abc){
document.write(e + "<BR>")
// 要直接访问属性,你就用 alert(abc.width); alert(abc.tt); alert(abc.height)
}
</script>
alula 2001-12-07
  • 打赏
  • 举报
回复
thanx
alula 2001-12-07
  • 打赏
  • 举报
回复
thanx!
alula 2001-12-07
  • 打赏
  • 举报
回复
多谢多谢!
多谢feijunjun(军仔):
for(var e in abc) { //。。。
加分加分

87,994

社区成员

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

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