<div class="codetitle"> <span><a style="CURSOR: pointer" data="98386" class="copybut" id="copybut98386" onclick="doCopy('code98386')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code98386"> <br><script type="text/javascript"> <BR><!-- <BR>var my={ <BR>str:'', <BR>deep:0, <BR>block:' ', <BR>get_pre:function(n) <BR>{ <BR>pre=''; <BR>for(i=0;i<n;i++) <BR>{ <BR>pre+=this.block; <BR>} <BR>return pre; <BR>}, <BR>show_obj:function(obj) <BR>{ <BR>for(k in obj) <BR>{ <BR>if(typeof(obj[k])!='object' && typeof(obj[k])!='array') <BR>{ <BR>pre=this.get_pre(this.deep); <BR>this.str+=pre+k+'=>'+obj[k]+'\n'; <BR>} <BR>else if(typeof(obj[k])=='object' && typeof(obj[k].length)=='undefined')//如果是对象 <BR>{ <BR>pre=this.get_pre(this.deep); <BR>this.str+=pre+k+'=>OBJECT{\n'; <BR>this.deep++;//开始递归,深度+1 <BR>this.show_obj(obj[k]); <BR>pre = this.get_pre(this.deep); <BR>this.deep--;//递归结束一个 深度-1 <BR>this.str+=pre+'}\n'; <BR>} <BR>else if(typeof(obj[k])=='object' && typeof(obj[k].length)!='undefined')//如果是数组 <BR>{ <BR>pre=this.get_pre(this.deep); <BR>this.str+=pre+k+'=>ARRAY[\n'; <BR>this.deep++;//同对象 <BR>this.show_obj(obj[k]); <BR>pre = this.get_pre(this.deep); <BR>this.deep--;//同对象 <BR>this.str+=pre+']\n'; <BR>} <BR>} <BR>return this.str; <BR>}, <BR>alert_obj:function(obj) <BR>{ <BR>alert(this.show_obj(obj)) <BR>} <BR>} <BR>my.alert_obj({a:{b:{c:{d:'hello world'}}}}); <BR>//--> <BR></script> <br> </div> <br>chrome 可以用 console.log <br>ie的话,