怎么拿到url地址?后的某个参数值

 1 function getSearchString(key){
 2     var str=location.search;
 3     str=str.substring(1,str.length);
 4     var arr=str.split("&"),obj={};
 5     if(arr.length){
 6         for(var i=0;i<arr.length;i++){
 7             var tmp_arr=arr[i].split("=");
 8             obj[decodeURI(tmp_arr[0])]=decodeURI(tmp_arr[1]);
 9         }
10     }
11     return obj[key];
12 }
13 getSearchString("fid");

location.search是从当前URL的?号开始的字符串,包含“?”在内。

decodeURI() 函数可对 encodeURI() 函数编码过的 URI 进行解码。

原文地址:https://www.cnblogs.com/qtx-/p/6805950.html