亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

用js寫了一個類似php的print_r輸出換行功能

 更新時間:2013年02月18日 11:24:18   作者:  
因?yàn)閜hp的print_r比較好用同時js卻沒有這個功能于是自己就寫了一個,感興趣的你可不要錯過了哈,希望本文對你提高知識有所幫助
復(fù)制代碼 代碼如下:

<script type="text/javascript">
<!--
var my={
str:'',
deep:0,
block:' ',
get_pre:function(n)
{
pre='';
for(i=0;i<n;i++)
{
pre+=this.block;
}
return pre;
},
show_obj:function(obj)
{
for(k in obj)
{
if(typeof(obj[k])!='object' && typeof(obj[k])!='array')
{
pre=this.get_pre(this.deep);
this.str+=pre+k+'=>'+obj[k]+'\n';
}
else if(typeof(obj[k])=='object' && typeof(obj[k].length)=='undefined')//如果是對象
{
pre=this.get_pre(this.deep);
this.str+=pre+k+'=>OBJECT{\n';
this.deep++;//開始遞歸,深度+1
this.show_obj(obj[k]);
pre = this.get_pre(this.deep);
this.deep--;//遞歸結(jié)束一個 深度-1
this.str+=pre+'}\n';
}
else if(typeof(obj[k])=='object' && typeof(obj[k].length)!='undefined')//如果是數(shù)組
{
pre=this.get_pre(this.deep);
this.str+=pre+k+'=>ARRAY[\n';
this.deep++;//同對象
this.show_obj(obj[k]);
pre = this.get_pre(this.deep);
this.deep--;//同對象
this.str+=pre+']\n';
}
}
return this.str;
},
alert_obj:function(obj)
{
alert(this.show_obj(obj))
}
}
my.alert_obj({a:{b:{c:{d:'hello world'}}}});
//-->
</script>

chrome 可以用 console.log
ie的話,

相關(guān)文章

最新評論