因此,假设我有一个非常基本的页面,其中包含一个正文、一个 div 和一个带有一些文本的段落元素。
<body>
<div>
<p>some text</p>
<div>
</body>
根据浏览器的不同,body/div 元素会有文本节点(nodeType === 3, nodeValue === "--blank--")。但是,P 元素将具有合法的文本节点,其 nodeValue === "some text"。
我想知道的是代表空白等于的“假”文本节点的“nodeValue”(--blank--)是什么,因为我想编写一个 if 测试,让我过滤掉假文本节点.
例子:
var body = document.getElementsByTagName("body")[0]; // shortcut to body element.
console.log(body.childNodes[0].nodeValue) // maps to one of the fake text nodes that are blank.
// returns a blank line. What is that "blank" equal to? It's not 'null' or "" or undefined...
干杯,亚历克斯