HTML DOM 文檔 anchors 屬性

定義和用法

不推薦使用 anchors 屬性。請請勿使用它。

anchors 屬性只返回那些有 name 屬性的 <a> 元素。

HTML5 不支持 <a> 元素的 name 属性。

替代方案:

文档中 <a> 元素的数量:

let num = document.getElementsByTagName("a").length;

親自試一試

第一個 <a> 元素的内容:

let content = document.getElementsByTagName("a")[0].innerHTML;

親自試一試

另請參考:

Anchor 對象

Document Links 集合

實例

例子 1

文档中 <a> 元素的数量:

let num = document.anchors.length;

親自試一試

例子 2

第一個 <a> 元素的内容:

let content = document.anchors[0].innerHTML;

親自試一試

語法

document.anchors

參數

Wala.

Return Value

Type Description
Obheheto HTMLCollection ng lahat ng <a> element na may name attribute sa dokumento.