js獲取頁面地址引數並將其轉化為一個物件

qq_45319821發表於2020-10-11

function getHref(){
var href = window.location.href,hrefArr = [],arr = [];
href = href.split("?")[1];
if(href == undefined){
return false;
}else{
hrefArr = href.split("&");
var obj = {};
$.each(hrefArr,function(i,item){
obj[item.split("=")[0]] = item.split("=")[1];
arr.push(obj);
})
if(obj){
return obj;
}
}
}

相關文章