ElementInternals: labels 屬性
ElementInternals 介面的只讀屬性 labels 返回與該元素關聯的標籤。
值
一個包含與該元素關聯的所有標籤元素的 NodeList。
示例
下面的示例展示了一個自定義複選框元件,其中包含一個與之關聯的 <label> 元素。將 labels 的值列印到控制檯會返回一個包含一個條目的 NodeList,代表該標籤。
html
<form id="myForm">
<custom-checkbox id="custom-checkbox"></custom-checkbox>
<label for="custom-checkbox">Join newsletter</label>
</form>
js
let element = document.getElementById("custom-checkbox");
console.log(element.internals_.label);
規範
| 規範 |
|---|
| HTML # dom-elementinternals-labels |
瀏覽器相容性
載入中…