我有以下 xml:
<Order>
<size width="16.5" height="19.5">
<width>16.5</width>
<height>19.5</height>
</size>
...
</Order>
我尝试了以下方法来获取宽度/高度的值:
width = parseFloat(doc.getElementsByTagName('width')[0].innerHTML);
height = parseFloat(doc.getElementsByTagName('height')[0].innerHTML);
但是在默认的 Android 浏览器和 IE 中,当我警告宽度时,我得到以下信息:NaN。此代码在 Chrome 中运行良好。
最佳答案
由于您有 XML,而不仅仅是 HTML,因此您应该使用 childNodes
和 nodeValue
:
width = parseFloat(doc.getElementsByTagName('width')[0].childNodes[0].nodeValue);
关于javascript - 我如何获取这个xml的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24512690/