aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/nodelist/values/index.html
blob: 36fb078e94ab3884b17f2a53e68a56fcb5b26d3d (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
---
title: NodeList.values()
slug: Web/API/NodeList/values
translation_of: Web/API/NodeList/values
---
<p>该方法返回一个iterator迭代器,可以利用迭代器遍历所有value。</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">nodeList.values();</pre>

<h3 id="Return_value">Return value</h3>

<p>Returns an {{jsxref("Iteration_protocols","iterator")}}.</p>

<h2 id="Example">Example</h2>

<pre class="brush: js;highlight:[13]">var node = document.createElement("div");
var kid1 = document.createElement("p");
var kid2 = document.createTextNode("hey");
var kid3 = document.createElement("span");

node.appendChild(kid1);
node.appendChild(kid2);
node.appendChild(kid3);

var list = node.childNodes;

// Using for..of
for(var value of list.values()) {
  console.log(value);
}
</pre>

<p>The result is:</p>

<pre>&lt;p&gt;
#text "hey"
&lt;span&gt;
</pre>

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat("api.NodeList.values")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{domxref("Node")}}</li>
 <li>{{domxref("NodeList")}}</li>
</ul>