//function
function getUrlParam(url, key) {
var reg = new RegExp("(^|&|\\?)" + key + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = url.match(reg); //匹配目标参数
if (r != null) return unescape(r[2]);
return null; //返回参数值
}
//eg
https://www.google.com/?gws_rd=ssl
var res = getUrlParam('https://www.google.com/?gws_rd=ssl', 'gws_rd');
console.log(res);
==> print 'ssl'
评论 (0)