我试图获取MonthDataLoaded标记的值,并且希望它返回Apr,但是当我向变量发出警报时,它将返回NaN。如果我抓住YearDataLoaded并发出警报,它将返回正确的2018值。是什么赋予了?

XML结果:

<BMSHealthReport>

<Site>Ft. Belvoir</Site>

<TotalUnits>349</TotalUnits>

<PercentReporting>85.39 %</PercentReporting>

<PercentNotReporting>14.61 %</PercentNotReporting>

<PercentBypassed>0.29 %</PercentBypassed>

<NumberLogins>52</NumberLogins>

<NumberAlarms>871</NumberAlarms>

<TotalEnergySavings>22,498</TotalEnergySavings>

<MonthDataLoaded>Apr </MonthDataLoaded>

<YearDataLoaded>2018</YearDataLoaded>

</BMSHealthReport>


我如何获取自己想要的特殊价值:

monthLoaded = xml.responseXML.xmlDoc.getElementByTagName("BMSHealthReport").parseFloat(x[1].getElementsByTagName("MonthDataLoaded")[0].childNodes[0].nodeValue);

alert(monthLoaded);

最佳答案

您正在尝试将字符串解析为浮点型,对于非数字型输入,它返回NaN。删除parseFloat调用:

monthLoaded = xml.responseXML.xmlDoc.getElementsByTagName("BMSHealthReport")[0].getElementsByTagName("MonthDataLoaded")[0].childNodes[0].nodeValue);

09-25 19:40