var parms = location.search.replace("?","").split("&");
var json = {};
for(let i = 0, n = parms.length; i<n; i++ ){
let t = parms[i].split("=");
json[ t[0] ] = t[1];
}
The JSON.parse method above is very convenient, but you need to consider the ie8-compatibility issue. The kind I wrote does not need to consider compatibility, but it is more troublesome
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
}
}
return theRequest;
}
function get_param(name){
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"),
r = window.location.search.substr(1).match(reg);
if(r!=null)return decodeURI(r[2]); return null;
}
Shouldn’t there be a query in location? Am I confused? . .
You can consider the following:
It may appear: "?a=1&b=2&c=", or even "?a=1&b=2&c"
"?id=001&from=1".replace('?', '').replace('&', ',').replace(/(w+)=(w+)/g, '$1:$2')
The JSON.parse method above is very convenient, but you need to consider the ie8-compatibility issue. The kind I wrote does not need to consider compatibility, but it is more troublesome
function GetRequest() {