我有一个带有一些GET参数的URL,如下所示:
www.test.com/t.html?a=1&b=3&c=m2-m3-m4-m5 我需要得到c的整个值。我试图读取网址,但我得到的只是m2。如何使用JavaScript完成此操作?
发布于 2019-03-28 19:32:50
从window.location中的搜索对象中提取所有url参数作为json
export const getURLParams = location => {
const searchParams = new URLSearchParams(location.search)
const params = {}
for (let key of searchParams.keys()) {
params[key] = searchParams.get(key)
}
return params
}
console.log(getURLParams({ search: '?query=someting&anotherquery=anotherthing' }))
// --> {query: "someting", anotherquery: "anotherthing"}https://stackoverflow.com/questions/979975
复制相似问题