一行代码装起来(URLSearchParams
)
1 | const getParams = (url = location.href) => { |
遍历searchParams
1 | const getParams = (url = location.href) => { |
正则获取
1.正则区别/(\w+)=(\w+)/
无法获取参数中的中文1
2
3
4
5
6
7
8
9const getParams = (url = location.href) => {
let arr = url.match(/([^?=&]+)=([^=&]+)/gi);
let obj = {};
arr.map(item => {
let [key, value] = item.split("=");
obj[key] = value;
})
return obj;
}
1 | const getParams = (url = location.href) => { |
获取url指定参数
1 | const getQueryString =(name)=> { |
1 | const getQueryString = (name, search) => { |