获取地址栏参数,最优解
获取地址栏参数,包括hash参数:
function getSearchParams(href = window.location.href) {
const temp = href.split(/[?#&]/), params = {};
temp.shift();
temp.forEach((item) => {
const param = item.split('=');
params[param[0]] = param[1];
});
return params;
}
const str = "http://www.baidu.com?a=1&b=2#c=3&d=4?e=5#f=6#g"
console.log(getSearchParams(str));