HTMLSelectElement.labels
只读特性返回
NodeList
的
<label>
elements associated with the
<select>
元素。
var labelElements = select.labels;
A
NodeList
containing the
<label>
elements associated with the
<select>
元素。
<label id="label1" for="test">Label 1</label> <select id="test"> <option value="1">Option 1</option> <option value="2">Option 2</option> </select> <label id="label2" for="test">Label 2</label>
window.addEventListener("DOMContentLoaded", function() {
const select = document.getElementById("test");
for(var i = 0; i < select.labels.length; i++) {
console.log(select.labels[i].textContent); // "Label 1" and "Label 2"
}
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'labels' in that specification. |
实时标准 | 无变化 |
|
HTML5
The definition of 'labels' in that specification. |
推荐 | 初始定义 |
The compatibility table in 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.
更新 GitHub 上的兼容性数据| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
labels
|
Chrome 14 | Edge 18 | Firefox 56 | IE No | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android 56 | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
完整支持
不支持
HTMLSelectElement
autofocus
被禁用
form
labels
选项
selectedIndex
selectedOptions
type
AbortController
AbortSignal
AbstractRange
Attr
ByteString
CDATASection
CSSPrimitiveValue
CSSValue
CSSValueList
CharacterData
ChildNode
注释
CustomEvent
DOMConfiguration
DOMError
DOMErrorHandler
DOMException
DOMImplementation
DOMImplementationList
DOMImplementationRegistry
DOMImplementationSource
DOMLocator
DOMObject
DOMParser
DOMPoint
DOMPointInit
DOMPointReadOnly
DOMRect
DOMString
DOMTimeStamp
DOMTokenList
DOMUserData
Document
DocumentFragment
DocumentType
元素
ElementTraversal
Entity
EntityReference
事件
EventTarget
HTMLCollection
MutationObserver
节点
NodeFilter
NodeIterator
NodeList
NonDocumentTypeChildNode
ProcessingInstruction
PromiseResolver
范围
StaticRange
文本
TextDecoder
TextEncoder
TimeRanges
TreeWalker
TypeInfo
USVString
UserDataHandler
XMLDocument