在一个AJAX查询,返回的XML文件。我可以解析的文件,但是当谈到获得的innerHTML(或在这种情况下,innerXML)的元素,这个问题就出现了。
After an AJAX query, a XML file is returned. I'm able to "parse" that file, but when it comes to getting the "innerHTML" (or in this case "innerXML") of an element, the issue arises.
如果XML元素,让我们说的内容,只包含文字我可以这样做: content.childNodes [0] .nodeValue
(假设的含量的引用XML元素内容)。但该元素包含其他元素:
If the XML element, let's say "content", only contained text I could do: content.childNodes[0].nodeValue
(assuming that content references the XML element "content"). But that element contains other elements:
<stackoverflow reason="tribute to this page">
<content>
<div><span><p>Some more HTML elements</p></span></div>
</content>
</stackoverflow>
我需要复制的含量&LT;内容&GT;
到现有的&LT; DIV&GT;
页面,我怎么能做到这一点?
I need to copy the content of <content>
to an existing <div>
in the page, how could I do that?
例。 myDiv.innerHTML = content.innerHTML;
的innerHTML
是你不应该使用在所有黑客攻击。相反,使用正常 DOM 功能:
innerHTML
is a hack you should not use at all. Instead, use the normal DOM functions:
myDiv.appendChild(document.adoptNode(content));