标签:style blog http color io os java ar strong
为了方便了解每个javascript对象包含的方法,我写一个函数。
1 function GetCollection(obj){ 2 try{ 3 if(obj){ 4 var sType=""; 5 var sMessage=""; 6 for (var i in obj){ 7 if(obj[i] ===null || obj[i] === undefined){ 8 sType="i"; 9 sMessage += "\r\n" + i; 10 } 11 else{ 12 var c = obj[i]; 13 if(c.name && c.value){ 14 sMessage += "\r\n" + (c.name + ":" + c.value); 15 sType="name:value"; 16 } 17 else{ 18 sMessage += "\r\n" + (i + "=" + obj[i]); 19 sType="obj[i]"; 20 } 21 } 22 } 23 sMessage += "\r\n" + ("sType:"+sType); 24 alert(sMessage); 25 } 26 } 27 catch(err){ 28 alert("err:" + err.message); 29 } 30 }
比如查看location的所有方法和值,可以通过下面js调用
GetCollection(location);
弹出界面如下:
也可以查看某个json的内容: var json ={"name":"张三","depart":"销售部","skill":["java","c++","PHP","c#"]};
GetCollection(json);
查看数组内容:
var arry =["1","5","c"];
GetCollection(arry);
标签:style blog http color io os java ar strong
原文地址:http://www.cnblogs.com/WebMobile/p/3968182.html