aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/urlsearchparams/entries/index.html
blob: 46e974035091ee01e3b9ce92a0488e7f4568db23 (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.entries()
slug: Web/API/URLSearchParams/entries
tags:
  - API
  - Experimental
  - Method
  - Reference
  - URL API
  - URLSearchParams
translation_of: Web/API/URLSearchParams/entries
---
<p>{{APIRef("URL API")}}{{SeeCompatTable}}</p>

<p><code><strong>URLSearchParams.entries()</strong></code>方法返回一个{{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.entries();</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&amp;key2=value2");

// 显示键/值对
for(var pair of searchParams.entries()) {
   console.log(pair[0]+ ', '+ pair[1]);
}
</pre>

<p>结果如下:</p>

<pre>key1, value1
key2, value2</pre>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<div>


<p>{{Compat("api.URLSearchParams.entries")}}</p>
</div>

<h2 id="另请参阅">另请参阅</h2>

<ul>
 <li>其他 URL相关接口: {{domxref("URL")}}, {{domxref("URLUtils")}}.</li>
</ul>