Skip to content

Instantly share code, notes, and snippets.

@fhefh2015
Created July 17, 2018 09:08
Show Gist options
  • Save fhefh2015/a50c98f7e266aecfd9d75be44f76f8f1 to your computer and use it in GitHub Desktop.
Save fhefh2015/a50c98f7e266aecfd9d75be44f76f8f1 to your computer and use it in GitHub Desktop.
获取URL参数
//正则方法
function getQueryString(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}
//拆分法
function GetRequest() {
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]] = unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment