HTMLOutputElement:labels 属性
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since October 2018.
HTMLOutputElement.labels
只读属性返回一个包含与 <output>
元素关联的 <label>
元素的 NodeList
。
值
一个包含与 <output>
元素关联的 <label>
元素的 NodeList
。
示例
HTML
html
<label id="label1" for="test">标签 1</label>
<output id="test">输出</output>
<label id="label2" for="test">标签 2</label>
JavaScript
js
window.addEventListener("DOMContentLoaded", () => {
const output = document.getElementById("test");
for (const label of output.labels) {
console.log(label.textContent); // “标签 1”和“标签 2“
}
});
规范
Specification |
---|
HTML # dom-lfe-labels-dev |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
labels |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.