Document.links

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

links 属性返回一个文档中所有具有 href 属性值的 <area> 元素与 <a> 元素的集合。

语法

nodeList = document.links

返回值

一个 HTMLCollection

示例

js
var links = document.links;
for (var i = 0; i < links.length; i++) {
  var linkHref = document.createTextNode(links[i].href);
  var lineBreak = document.createElement("br");
  document.body.appendChild(linkHref);
  document.body.appendChild(lineBreak);
}

规范

Specification
HTML Standard
# dom-document-links-dev

浏览器兼容性

BCD tables only load in the browser