HTMLButtonElement: labels 属性
HTMLButtonElement.labels 只读属性返回一个 NodeList,其中包含与 <button> 元素关联的 <label> 元素。
值
一个包含与 <button> 元素关联的 <label> 元素的 NodeList。
示例
HTML
html
<label id="label1" for="test">Label 1</label>
<button id="test">Button</button>
<label id="label2" for="test">Label 2</label>
JavaScript
js
const button = document.getElementById("test");
for (const label of button.labels) {
console.log(label.textContent); // "Label 1" and "Label 2"
}
规范
| 规范 |
|---|
| HTML # dom-lfe-labels-dev |
浏览器兼容性
加载中…