您的位置:首页 > 其它

使用原生方法获取地址栏参数

2017-08-24 15:15 323 查看
var getUrlParam = function(name){
var reg=new RegExp("(^|&)"+name+"=([^&]*)(&|$)"),
r = window.location.search.substr(1).match(reg);
console.log(window.location.search)
if (r!=null){
return unescape(r[2]);
}else {
return null;
}
}
//   http://localhost:8000?param=1 console.log( getUrlParam("param")) //  输出1  字符串型
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: