标签:ack 没有 不同 nod isp blank 用法 span node
目录结构:
Note.noteValue 属性返回或设置当前属性的值。
value = node.nodeValue;
如果有值的话,value则是一个包含当前节点值的字符串,如果没有则是null。
对于document文档自身来说,nodeValue返回null。对于元素节点,nodeValue返回null。对于文本节点、注释和CDATA部分来说,noteValue返回其节点的内容。 对于节点属性来说,属性的值将会被返回。
下面的表列出了不同元素的返回值,
| Attr | value of attribute |
|---|---|
| CDATASection | content of the CDATA Section |
| Comment | content of the comment |
| Document | null |
| DocumentFragment | null |
| DocumentType | null |
| Element | null |
| NamedNodeMap | null |
| EntityReference | null |
| Notation | null |
| ProcessingInstruction | entire content excluding the target |
| Text | content of the text node |
<!DOCTYPE html> <html> <head> <title>noteValue.html</title> <meta name="content-type" content="text/html; charset=UTF-8"> </head> <body> <div id="emp"></div> <div id="full">I hava contents</div> <script> //返回null var val1=document.nodeValue; //返回null,因为val2代表的是一个元素节点的noteValue。 var val2=document.getElementById("emp").nodeValue; //报错,因为val3代表的节点无子节点 var val3=document.getElementById("emp").firstChild.nodeValue; //返回null,因为val4代表的是一个元素节点的noteValue. var val4=document.getElementById("full").nodeValue; //返回一个"I hava contents",因为val5代表的是一个文本节点的子节点 var val5=document.getElementById("full").firstChild.nodeValue; </script> </body> </html>
本文为博主原创翻译,如需转载请注明出处。
标签:ack 没有 不同 nod isp blank 用法 span node
原文地址:http://www.cnblogs.com/HDK2016/p/6165229.html