这篇文章与Convert a HTml String to DOM and then DOM to formatted Text
有关我有以下DOM字符串
<DIV STYLE="text-align:Left;font-family:Segoe UI;font-style:normal;font-weight:normal;font-size:12;color:#000000;">
<P STYLE="margin:0 0 0 0;">
<SPAN><SPAN>Lee is an attentive listener who tunes into the task at hand and follows instructions.
</SPAN></SPAN></P><P />
<P STYLE="margin:0 0 0 0;">
<SPAN>
<SPAN>In our reading lessons we have been working on books from Levels 6 to 9 with support given as needed.
</SPAN></SPAN></P><P />
<P STYLE="margin:0 0 0 0;">
<SPAN>
<SPAN>Lee can write his own simple stories and recounts of 2 or 3 sentences.
</SPAN></SPAN></P><P />
</Div>
当我使用DOMParser解析此字符串时,它会创建
doc.firstChild.textContent as
Lee is an attentive listener who tunes into the task at hand and follows instructions. In our reading lessons we have been working on books from Levels 6 to 9 with support given as needed.Lee can write his own simple stories and recounts of 2 or 3 sentences.
doc.firstChild.children.length为7
doc.firstChild.children.item(0)as
Lee is an attentive listener who tunes into the task at hand and follows instructions
doc.firstChild.children.item(1)为null
doc.firstChild.children.item(2)as
In our reading lessons we have been working on books from Levels 6 to 9 with support given as needed.
doc.firstChild.children.item(4)as
Lee can write his own simple stories and recounts of 2 or 3 sentences.
所有其他项目都为空
此外,上述所有7个孩子都有nodeName P
对我来说真的没有意义
当我将它附加到我的表格单元格时,段落之间也没有间距。
$(".test").get(elementPos).appendChild(doc.firstChild);
var parser = new DOMParser();
var doc = parser.parseFromString(replaced, "text/xml");