Attr.localName
read-only property returns the local part of the qualified name of an attribute.
In previous DOM specifications this API was defined within the
节点
接口。
name = attribute.localName
A
DOMString
representing the local part of the attribute's qualified name.
The following example shows "id" in an alert dialog.
<button id="example">Click me</button>
const element = document.querySelector("#example");
element.addEventListener("click", function() {
const attribute = element.attributes[0];
alert(attribute.localName);
});
The local name of an attribute is the part of the attribute's qualified name that comes after the colon. Qualified names are typically used in XML as part of the namespace(s) of the particular XML documents.
注意: 在 Gecko 1.9.2 and earlier, the property returns the upper-cased version of the local name for HTML attributes in HTML DOMs (as opposed to XHTML attributes in XML DOMs). In later versions, in compliance with HTML5, the property returns in the case of the internal DOM storage, which is lower case for both HTML attributes in HTML DOMs and XHTML attributes in XML DOMs.
| 规范 | 状态 | 注释 |
|---|---|---|
|
DOM
The definition of 'Attr.localName' in that specification. |
实时标准 | 初始定义 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
localName
|
Chrome
46
|
Edge ≤18 |
Firefox
48
|
IE No |
Opera
33
|
Safari 1.3 |
WebView Android
46
|
Chrome Android
46
|
Firefox Android
48
|
Opera Android
33
|
Safari iOS 1 |
Samsung Internet Android
5.0
|
完整支持
不支持
见实现注意事项。
Attr
localName
namespaceURI
prefix
AbortController
AbortSignal
AbstractRange
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