Node
的 nodeValue
属性返回或设置当前节点的值。
语法
str = node.nodeValue; node.nodeValue = str;
value是一个包含当前节点的值的字符串(如果有的话)。
值
对于文档节点来说, nodeValue
返回null
. 对于text, comment, 和 CDATA 节点来说, nodeValue返回该节点的文本内容
. 对于 attribute 节点来说, 返回该属性的属性值.
下表就是不同类型的节点所返回的该属性的值.
Node | Value of nodeValue |
---|---|
CDATASection |
CDATA的文本内容 |
Comment |
注释的文本内容 |
Document |
null |
DocumentFragment |
null |
DocumentType |
null |
Element |
null |
NamedNodeMap |
null |
EntityReference |
null |
Notation |
null |
ProcessingInstruction |
整个标签的文本内容 |
Text |
文本节点的内容 |
如果nodeValue的值为
null
,则对它赋值也不会有任何效果.
规范
Specification | Status | Comment |
---|---|---|
DOM Node: nodeValue |
Living Standard |
Browser compatibility
BCD tables only load in the browser
The compatibility table on 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.