Skip to content

Instantly share code, notes, and snippets.

@foru17
Created June 12, 2015 06:41
Show Gist options
  • Save foru17/2d1f9f372bfede270ee2 to your computer and use it in GitHub Desktop.
Save foru17/2d1f9f372bfede270ee2 to your computer and use it in GitHub Desktop.
获得URL中的参数
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数
if (r != null) return unescape(r[2]);
return null; //返回参数值
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment