File tree Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ div.nodeName // "DIV"
68
68
69
69
` nodeValue ` 属性返回一个字符串,表示当前节点本身的文本值,该属性可读写。
70
70
71
- 只有文本节点(text)和注释节点 (comment)有文本值,因此这两类节点的 ` nodeValue ` 可以返回结果,其他类型的节点一律返回` null ` 。同样的,也只有这两类节点可以设置 ` nodeValue ` 属性的值,其他类型的节点设置无效。
71
+ 只有文本节点(text)、注释节点 (comment)和属性节点(attr) 有文本值,因此这三类节点的 ` nodeValue ` 可以返回结果,其他类型的节点一律返回` null ` 。同样的,也只有这三类节点可以设置 ` nodeValue ` 属性的值,其他类型的节点设置无效。
72
72
73
73
``` javascript
74
74
// HTML 代码如下
@@ -102,7 +102,7 @@ document.getElementById('foo').textContent = '<p>GoodBye!</p>';
102
102
103
103
上面代码在插入文本时,会将` <p> ` 标签解释为文本,而不会当作标签处理。
104
104
105
- 对于文本节点(text)和注释节点 (comment),` textContent ` 属性的值与` nodeValue ` 属性相同。对于其他类型的节点,该属性会将每个子节点的内容连接在一起返回,但是不包括注释节点 。如果一个节点没有子节点,则返回空字符串。
105
+ 对于文本节点(text)、注释节点 (comment)和属性节点(attr) ,` textContent ` 属性的值与` nodeValue ` 属性相同。对于其他类型的节点,该属性会将每个子节点(不包括注释节点)的内容连接在一起返回 。如果一个节点没有子节点,则返回空字符串。
106
106
107
107
文档节点(document)和文档类型节点(doctype)的` textContent ` 属性为` null ` 。如果要读取整个文档的内容,可以使用` document.documentElement.textContent ` 。
108
108
You can’t perform that action at this time.
0 commit comments