Skip to content

Instantly share code, notes, and snippets.

@fengxuway
Created August 4, 2016 03:06
Show Gist options
  • Save fengxuway/f555d6da02a2628581769c47c9a0456e to your computer and use it in GitHub Desktop.
Save fengxuway/f555d6da02a2628581769c47c9a0456e to your computer and use it in GitHub Desktop.
获取URL的参数值
function getParam(name, url) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
if (!url){
url = window.location.href;
}
if(url.indexOf("?") <0){
return null;
}
var query = url.substr(url.indexOf("?"), url.length);
var r = query.substr(1).match(reg);
if (r != null)
return decodeURI(r[2]);
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment