【发布时间】:2012-01-19 03:25:13
【问题描述】:
可能重复:
Use the get paramater of the url in javascript
How can I get query string values in JavaScript?
在 Javascript 中,如何获取 URL 字符串(不是当前 URL)的参数?
喜欢:
www.domain.com/?v=123&p=hello
我可以在 JSON 对象中获取“v”和“p”吗?
【问题讨论】:
-
你可以看看这个帖子stackoverflow.com/questions/901115/…
-
这是一个不错的小snippet。
-
其中一个重复的问题是a great answer using the native, modern built-in
URLSearchParamsobject。另见MDN's doc page。 Polyfills 可用。 -
一个班轮:
new URL("http://www.example.com/?v=123&p=hello").searchParams.toString().split("&").reduce((previous, current)=> { const [key, value] = current.split("="); previous[key] = value; return previous },{})
标签: javascript url query-string string-parsing