/**
* 解析url参数
* @example ?id=123&a=b
* @return Object {id:123,a:b}
*/
export function urlParse() {
let url = window.location.search;
let obj = {};
let reg = /[?&][^?&]+=[^?&]+/g;
var arr = url.match(reg);
if (arr) {
arr.forEach((item) => {
let tempArr = item.substr(1).split('=');
let key = decodeURIComponent(tempArr[0]);
let value = decodeURIComponent(tempArr[1]);
obj[key] = value;
});
}
return obj;
};
解析url
最新推荐文章于 2026-04-14 08:27:32 发布
本文介绍了一个用于解析URL中查询参数的JavaScript函数。该函数通过正则表达式匹配所有查询参数,并将其转换为一个易于操作的对象形式。

9285

被折叠的 条评论
为什么被折叠?



