var atr = 'http://item.taobao.com/item.html?a=1';
function geturlJson () {
var datastr = atr.split("?")[1];
console.log(datastr)
var result = {};
if(datastr.indexOf("&") > 0 ){
var bigarr = datastr.split("&");
console.log(bigarr)
for (var i= 0 ;i<bigarr.length;i++){
var smallarr= bigarr[i].split("=");
result[smallarr[0]] = smallarr[1];
}
}else{
var arrr= datastr.split("=");
result[arrr[0]] = arrr[1];
console.log(result)
}
return result;
}
geturlJson()
转载于:https://www.cnblogs.com/honeywei/p/8243263.html