diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/url/searchparams | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/url/searchparams')
-rw-r--r-- | files/zh-cn/web/api/url/searchparams/index.html | 56 |
1 files changed, 56 insertions, 0 deletions
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 +--- +<div>{{APIRef("URL API")}}</div> + +<p>{{domxref("URL")}} 接口的 <strong><code>searchParams</code></strong> 属性返回一个 {{domxref("URLSearchParams")}} 对象,这个对象包含当前 URL 中解码后的 {{httpmethod("GET")}} 查询参数。</p> + +<p>{{AvailableInWorkers}}</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox notranslate">const <em>urlSearchParams</em> = <em>url</em>.searchParams</pre> + +<h3 id="属性值">属性值</h3> + +<p>一个 {{domxref("URLSearchParams")}} 对象。</p> + +<h2 id="例子">例子</h2> + +<p>如果你的 URL 是 <code>https://example.com/?name=Jonathan&age=18</code> ,你可以这样解析 URL,然后得到 <code>name</code> 和 <code>age</code> 的值。</p> + +<pre class="brush: js notranslate">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</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">规范</th> + <th scope="col">状态</th> + <th scope="col">备注</th> + </tr> + <tr> + <td>{{SpecName('URL', '#dom-url-searchparams', 'searchParams')}}</td> + <td>{{Spec2('URL')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.URL.searchParams")}}</p> |