HTMLInputElement.labels
只读特性返回
NodeList
的
<label>
elements associated with the
<input>
元素。
var labelElements = input.labels;
A
NodeList
containing the
<label>
elements associated with the
<input>
元素。
<label id="label1" for="test">Label 1</label> <input id="test"/> <label id="label2" for="test">Label 2</label>
window.addEventListener("DOMContentLoaded", function() {
const input = document.getElementById("test");
for(var i = 0; i < input.labels.length; i++) {
console.log(input.labels[i].textContent); // "Label 1" and "Label 2"
}
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'labels' in that specification. |
实时标准 | 无变化 |
|
HTML5
The definition of 'labels' in that specification. |
推荐 | 初始定义 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
labels
|
Chrome 14 | Edge 18 | Firefox 56 | IE 不支持 No | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android Yes | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
完整支持
不支持
HTMLInputElement
labels
multiple
webkitdirectory
webkitEntries
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