JavaScript 如何遍历得到控件的所有属性? 困惑了好长时间的问题!!!! 分不够说话.

iamnewsea 2006-07-09 01:51:53
如题:
JavaScript 如何遍历得到控件的所有属性?
...全文
322 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xishanlang2001 2006-07-09
  • 打赏
  • 举报
回复
<span a=1 b=2 c=3 onclick="test(this)">点击查看我的属性集</span>
<br>
<br>
<div id=result></div>
<script>
function test( the )
{
var str = "" ;
for( var i = 0 ; i < the.attributes.length ; i++ )
{
str += "nodeName:" + the.attributes[ i ].nodeName + "<br>" ;
str += "nodeType:" + the.attributes[ i ].nodeType + "<br>" ;
str += "nodeValue:" + the.attributes[ i ].nodeValue + "<br>" ;
str += "name:" + the.attributes[ i ].name + "<br>" ;
str += "specified:" + the.attributes[ i ].specified + "<br>" ;
str += "expando:" + the.attributes[ i ].expando + "<br>" ;
str += "<br>---------------<br>"
}
result.innerHTML = str
}
</script>
iamnewsea 2006-07-09
  • 打赏
  • 举报
回复
即如何得到子属性的个数.
iamnewsea 2006-07-09
  • 打赏
  • 举报
回复
好,谢谢
还有.
如果这个属性对象还有属性,怎么遍历属性的属性.
是是非非 2006-07-09
  • 打赏
  • 举报
回复
for(var s in window){
alert('window.'+s+' = '+window[s]);
}

87,992

社区成员

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

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