ElementInternals:labels 属性
Baseline
2023
Newly available
Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
ElementInternals
接口的 labels
只读属性返回与该元素关联的标签。
值
一个包含与此元素关联的所有标签元素的 NodeList
。
示例
以下示例显示了一个自定义复选框组件,其中有一个与之关联的 <label>
元素。将 labels
的值打印到控制台会返回一个包含表示此标签的条目 NodeList
。
html
<form id="myForm">
<custom-checkbox id="custom-checkbox"></custom-checkbox>
<label for="custom-checkbox">加入时事通讯</label>
</form>
js
let element = document.getElementById("custom-checkbox");
console.log(element.internals_.label);
规范
Specification |
---|
HTML> # dom-elementinternals-labels> |
浏览器兼容性
Loading…