本文介绍了为什么nodeName有时在DOM DOM中全部覆盖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个DOM文件看起来基本上就像这样

So I have a DOM document that looks essentially like this

<categories>
    <category id="1"/>
    <category id="2"/>
</categories>

正如我所料,Firebug中的文档是如何预览的。

This is how the document previews in Firebug, as I would expect.

然而,当我把它发送到服务器时,我得到

However, when I POST this to the server, I get

<categories>
    <CATEGORY id="1"/>
    <CATEGORY id="2"/>
</categories>

的确,doc.documentElement.firstChild.nodeName返回CATEGORY。使用jQuery.append('< category />')添加节点。

Indeed, doc.documentElement.firstChild.nodeName returns "CATEGORY". The nodes are added using jQuery.append('<category/>').

为什么在所有大写中返回子标签?

Why are the child tags returned in all caps?

推荐答案

然而,nodeName总是返回被视为HTML ...的DOM中的HTML元素的大写名称,而不是XML。

nodeName always returns the upper case name for HTML elements in DOMs treated as HTML ... not so for XML, however.

我不知道这是否完全能够回答您的问题,但我猜测这部分答案是将您的文件视为HTML文档,至少在nodeName

I'm not sure if this totally answers your question, but I'm guessing that part of the answer is your file is being treated like an HTML document, at least as far as nodeName is concerned.

更正:这是JQuery ,处理像HTML这样的东西。从:

Correction: It's JQuery that's treating things like HTML. From this previous Stack Overflow answer:

我很确定你遇到了同样的问题如之前的答案。

I'm pretty sure you're experiencing the same issue as in that previous answer.

这篇关于为什么nodeName有时在DOM DOM中全部覆盖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 03:35