引用原文:http://www.cnblogs.com/lishenglyx/archive/2008/12/08/1350573.html#undefined
<script language="javascript">
var obj = new Object();
obj.myname = "我是对象";
obj.pro2 = "23";
obj.pro3 = "abcdeg"; php程序员之家
for (items in obj){
document.write("属性:"+items+"的值是 ("+ obj[items] +")");
document.write("<br>");
}
</script>
遍历方法(就多一个var,不会吧
for (var o in WordsList) {
document.write(o+"<br/>");
}
- function allPrpos(obj) {
- // 用来保存所有的属性名称和值
- var props = "";
- // 开始遍历
- for(var p in obj){
- // 方法
- if(typeof(obj[p])=="function"){
- obj[p]();
- }else{
- // p 为属性名称,obj[p]为对应属性的值
- props+= p + "=" + obj[p] + ""t";
- }
- }
- // 最后显示所有的属性
- alert(props);
- }