合并文本节点

 1 var element = document.createElement("div");

 2 element.className = "message";

 3 

 4 var textNode = document.createTextNode("Hello world!");

 5 element.appendChild(textNode);

 6 

 7 var anotherTextNode = document.createTextNode("Yippee!");

 8 element.appendChild(anotherTextNode);

 9 

10 document.body.appendChild(element);

11 

12 console.log(element.childNodes.length); //2

13 

14 element.normalize();

15 console.log(element.childNodes.length); //1

16 console.log(element.firstChild.nodeValue); //Hello world!Yippee! 

你可能感兴趣的:(合并)