有一个url file:///android_asset/hrfile/html/review/reveiw_cc.html?id=1111&sessionid=ssssssssssssssss&domain=http://10.0.100.110:8080/jeesite/a
//获取 参数 param
var getParam = {
href :function(){
var href ="file:///android_asset/hrfile/html/review/reveiw_cc.html? id=1111&sessionid=ssssssssssssssss&domain=http://10.0.100.110:8080/j eesite/a/";
var params = href.split("?")[1];
var paramArr = params.split('&');
var res = {};
for(vari = 0;i<paramArr.length;i++){
var str = paramArr[i].split('=');
res[str[0]]=str[1];
}
returnres;
},
jsessionid :function(){
var obj = getParam.href();
return obj.sessionid
} ,
id:function(){
var obj = getParam.href();
return obj.id
},
domain :function(){
var obj = getParam.href();
return obj.domain
}
}
var parseParam = function(param,key){
var paramStr="";
if(paraminstanceofString||paraminstanceofNumber||paraminstanceofBoolean){
paramStr+="&"+key+"="+encodeURIComponent(param);
}else{
$.each(param,function(i){
vark=key==null?i : key+(paraminstanceofArray?"["+i+"]":"."+i);
paramStr+='&'+parseParam(this,k);
})
}
return paramStr.substr(1);
};
var obj={
"name":'tom',
"class":{"className":'class1'},
"classMates":[{"name":'lily'}]
};
console.log(parseParam(obj));
//name=tom&class.className=class1&classMates[0].name=lily
console.log(parseParam(obj,'stu'));
//stu.name=tom&stu.class.className=class1&stu.classMates[0].name=lily