js 获取地址栏参数的方法:
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;
}
比如当前地址为:http://baidu.com/?id=100&name=sanfeng
let id = getUrlParam('id');
let name = getUrlParam('name');
console.log(id) //100
console.log(id) // sanfeng
网友评论