为了方便了解每个javascript对象包含的方法,我写一个函数。
function GetCollection(obj){
try{
if(obj){
var sType="";
var sMessage="";
for (var i in obj){
if(obj[i] ===null || obj[i] === undefined){
sType="i";
sMessage += "\r\n" + i;
}
else{
var c = obj[i];
if(c.name && c.value){
sMessage += "\r\n" + (c.name + ":" + c.value);
sType="name:value";
}
else{
sMessage += "\r\n" + (i + "=" + obj[i]);
sType="obj[i]";
}
}
}
sMessage += "\r\n" + ("sType:"+sType);
alert(sMessage);
}
}
catch(err){
alert("err:" + err.message);
}
}
比如查看location的所有方法和值,可以通过下面js调用
GetCollection(location);
弹出界面如下:
也可以查看某个json的内容: var json ={"name":"张三","depart":"销售部","skill":["java","c++","PHP","c#"]};
GetCollection(json);
查看数组内容:
var arry =["1","5","c"];
GetCollection(arry);