From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/url/searchparams/index.html | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 files/zh-cn/web/api/url/searchparams/index.html (limited to 'files/zh-cn/web/api/url/searchparams') diff --git a/files/zh-cn/web/api/url/searchparams/index.html b/files/zh-cn/web/api/url/searchparams/index.html new file mode 100644 index 0000000000..d4d775aed0 --- /dev/null +++ b/files/zh-cn/web/api/url/searchparams/index.html @@ -0,0 +1,56 @@ +--- +title: URL.searchParams +slug: Web/API/URL/searchParams +tags: + - API + - URL + - 参考 + - 只读 + - 只读属性 + - 属性 +translation_of: Web/API/URL/searchParams +--- +
{{APIRef("URL API")}}
+ +

{{domxref("URL")}} 接口的 searchParams 属性返回一个 {{domxref("URLSearchParams")}} 对象,这个对象包含当前 URL 中解码后的 {{httpmethod("GET")}} 查询参数。

+ +

{{AvailableInWorkers}}

+ +

语法

+ +
const urlSearchParams = url.searchParams
+ +

属性值

+ +

一个 {{domxref("URLSearchParams")}} 对象。

+ +

例子

+ +

如果你的 URL 是 https://example.com/?name=Jonathan&age=18 ,你可以这样解析 URL,然后得到 nameage 的值。

+ +
let params = (new URL(document.location)).searchParams;
+let name = params.get('name'); // is the string "Jonathan Smith".
+let age = parseInt(params.get('age')); // is the number 18
+ +

规范

+ + + + + + + + + + + + + + +
规范状态备注
{{SpecName('URL', '#dom-url-searchparams', 'searchParams')}}{{Spec2('URL')}}Initial definition.
+ +

浏览器兼容性

+ + + +

{{Compat("api.URL.searchParams")}}

-- cgit v1.2.3-54-g00ecf