HTMLProgressElement:labels 属性

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.

HTMLProgressElement.labels 只读属性返回一个与 <progress> 元素有关联的 <label> 元素的 NodeList

一个与 <progress> 元素有关联的 <label> 元素的 NodeList

示例

HTML

html
<label id="label1" for="test">标签 1</label>
<progress id="test" value="70" max="100">70%</progress>
<label id="label2" for="test">标签 2</label>

JavaScript

js
window.addEventListener("DOMContentLoaded", () => {
  const progress = document.getElementById("test");
  for (const label of progress.labels) {
    console.log(label.textContent); // “标签 1”和“标签 2”
  }
});

规范

Specification
HTML Standard
# dom-lfe-labels-dev

浏览器兼容性

BCD tables only load in the browser