aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/document/links/index.html
blob: a5df44e0c6b712b3fe086b55f18651bbc7c4fa7e (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
58
59
60
---
title: Document.links
slug: Web/API/Document/links
tags:
  - API
  - Document
  - 属性
translation_of: Web/API/Document/links
---
<p>{{APIRef("DOM")}}</p>

<p><code>links</code> 属性返回一个文档中所有具有 href 属性值的 {{HTMLElement("area")}} 元素与 {{HTMLElement("a")}} 元素的集合。</p>

<h3 id="语法">语法</h3>

<pre class="syntaxbox"><em>nodeList</em> = document.links </pre>


<h3 id="返回值">返回值</h3>

<p>一个 {{domxref("HTMLCollection")}}</p>

<h3 id="示例">示例</h3>

<pre class="brush: js">var links = document.links;
for(var i = 0; i &lt; links.length; i++) {
  var linkHref = document.createTextNode(links[i].href);
  var lineBreak = document.createElement("br");
  document.body.appendChild(linkHref);
  document.body.appendChild(lineBreak);
}
</pre>

<h3 id="规范">规范</h3>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">规范</th>
   <th scope="col">状态</th>
   <th scope="col">备注</th>
  </tr>
  <tr>
   <td>{{SpecName('HTML WHATWG', '#dom-document-links', 'Document.links')}}</td>
   <td>{{ Spec2('HTML WHATWG') }}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName("DOM2 HTML", "html.html#ID-7068919", "document.links")}}</td>
   <td>{{Spec2("DOM2 HTML")}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

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



<p>{{Compat("api.Document.links")}}</p>