nodeName
read-only property returns the name of the current
节点
以字符串形式。
var str = node.nodeName;
A
DOMString
. Values for the different types of nodes are:
| 接口 | nodeName value |
|---|---|
Attr
|
值
Attr.name
|
CDATASection
|
"#cdata-section"
|
注释
|
"#comment"
|
Document
|
"#document"
|
DocumentFragment
|
"#document-fragment"
|
DocumentType
|
值
DocumentType.name
|
元素
|
值
Element.tagName
|
Entity
|
The entity name |
EntityReference
|
The name of entity reference |
Notation
|
The notation name |
ProcessingInstruction
|
值
ProcessingInstruction.target
|
文本
|
"#text"
|
Given the following markup:
<div id="d1">hello world</div> <input type="text" id="t">
and the following script:
var div1 = document.getElementById("d1");
var text_field = document.getElementById("t");
text_field.value = div1.nodeName;
In XHTML (or any other XML format),
text_field
's value would read
"div"
. However, in HTML,
text_field
's value would read
"DIV"
,因为
nodeName
and
tagName
return in upper case on HTML elements in DOMs flagged as HTML documents. Read more
details on nodeName case sensitivity in different browsers
.
注意,
Element.tagName
property could have been used instead, since
nodeName
has the same value as
tagName
for an element. Bear in mind, however, that
nodeName
将返回
"#text"
for text nodes while
tagName
将返回
undefined
.
| 规范 | 状态 | 注释 |
|---|---|---|
|
DOM
The definition of 'nodeName' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
nodeName
|
Chrome Yes | Edge 12 | Firefox Yes | IE ? | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android Yes | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
完整支持
兼容性未知
节点
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