我正在尝试获取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);
答案 0 :(得分:1)
您正在尝试将字符串解析为float,它会返回NaN
非类似数字的输入。删除parseFloat
电话:
monthLoaded = xml.responseXML.xmlDoc.getElementsByTagName("BMSHealthReport")[0].getElementsByTagName("MonthDataLoaded")[0].childNodes[0].nodeValue);