如何獲取瀏覽器url參數轉化為json序列
var GetQueryJson1=function(){ let url=location.href;//獲取當前瀏覽器的URL let arr=[];//存儲參數的數組 let res={};//存儲最終JSON結果對象 arr=url.split('?')[1].split('&');//獲取瀏覽器地址欄中的參數 for(let i=0;i<arr.length;i++){//遍歷參數 if(arr[i].indexOf('=')!=-1){//如果參數中有值 let str=arr[i].split('='); res[str[0]]=str[1]; }else{//如果參數中無值 res[arr[i]]=''; } } return res; } console.log(GetQueryJson1());