function Person(){ this.name="bai"; this.age=19; this.height=175; } var p1= new Person(); var temp,p1Str=""; for(temp in p1){ alert(typeof temp); --是字符串 alert(p1[temp]); p1Str=p1Str+temp+" -- " } alert(p1Str); --返回"name -- age -- height"
------解决方案--------------------
------解决方案-------------------- 楼主得到答案了吗?结果呢
------解决方案-------------------- for(i in test){ alert(test[i]); }
------解决方案-------------------- var test = document.getElementById('test'); for(i in test){ alert(test[i]); }
------解决方案-------------------- 推荐你用一下Jquery,看有没有这样的例子,Jquery里有attribute的一些方法,试一下
------解决方案--------------------
------解决方案--------------------
HTML code
<html>
<head>
<title> </title>
</head>
<body>
<input id="test" name="hehe" styple="" />
<br/>
<script type="text/javascript">
var o = document.getElementById("test");
for (var p in o) {
document.write("<b>"+p+":</b>");
document.write(escapeXml(o[p]+""));
document.write("<br/>");
}
function escapeXml(str) {
return str.replace(/&/g, "&").replace(/\</g, "<").replace(/>/g, ">");
}
</script>
</body>
</html>