blob: 2ff71529b31cce949d608380778b4554569132f0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
---
title: URLSearchParams.keys()
slug: Web/API/URLSearchParams/keys
tags:
- API
- Experimental
- Method
- Reference
- URL API
- URLSearchParams
translation_of: Web/API/URLSearchParams/keys
---
<p>{{APIRef("URL API")}}{{SeeCompatTable}}</p>
<p>URLSearchParams.keys()返回一个{{jsxref("Iteration_protocols",'iterator')}},遍历器允许遍历对象中包含的所有键。这些键都是{{domxref("USVString")}}对象。</p>
<div class="note">
<p><strong>注意</strong>: 该方法在 <a href="/en-US/docs/Web/API/Web_Workers_API">Web Workers</a>中也可使用</p>
</div>
<h2 id="语法">语法</h2>
<pre class="syntaxbox">searchParams.keys();</pre>
<h3 id="返回值">返回值</h3>
<p>返回一个{{jsxref("Iteration_protocols","iterator")}}.</p>
<h2 id="例子">例子</h2>
<pre class="brush: js;highlight:[5]">// 建立一个测试用URLSearchParams对象
var searchParams = new URLSearchParams("key1=value1&key2=value2");
// 输出键值对
for(var key of searchParams.keys()) {
console.log(key);
}
</pre>
<p>结果如下:</p>
<pre>key1
key2</pre>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<div>
<p>{{Compat("api.URLSearchParams.keys")}}</p>
</div>
<h2 id="另请参考">另请参考</h2>
<ul>
<li>其他URL相关接口: {{domxref("URL")}}, {{domxref("URLUtils")}}.</li>
</ul>
|