我正在使用 jQuery 从网页中提取一些数据,它以数组的形式返回,其中包含我正在尝试添加的以下值(.5、.25、1.25、3.75)。这是我的代码片段:
var th = 0;
for (thisrow in objGrid) {
var hours = objGrid[thisrow]['hours'];
th = th+parseFloat(hours);
console.log(hours);
$("#msgbox").html("Showing records for week: " + thisDate + ". Total Hours for the week : " + th);
}
在 console.log 中,我得到了几个小时 - 0, 0, 1, 3,总共 4 个。如果我不使用 parseFloat,我仍然会得到相同的结果,(以为我会得到 NaN)。我究竟做错了什么?