欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

用js寫(xiě)了一個(gè)類(lèi)似php的print_r輸出換行功能

 更新時(shí)間:2013年02月18日 11:24:18   作者:  
因?yàn)閜hp的print_r比較好用同時(shí)js卻沒(méi)有這個(gè)功能于是自己就寫(xiě)了一個(gè),感興趣的你可不要錯(cuò)過(guò)了哈,希望本文對(duì)你提高知識(shí)有所幫助
復(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')//如果是對(duì)象
{
pre=this.get_pre(this.deep);
this.str+=pre+k+'=>OBJECT{\n';
this.deep++;//開(kāi)始遞歸,深度+1
this.show_obj(obj[k]);
pre = this.get_pre(this.deep);
this.deep--;//遞歸結(jié)束一個(gè) 深度-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++;//同對(duì)象
this.show_obj(obj[k]);
pre = this.get_pre(this.deep);
this.deep--;//同對(duì)象
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的話(huà),

相關(guān)文章

最新評(píng)論