我使用下面的代码使用JavaScript添加整数和浮点值。但我不能这样做,它会返回NaN
。我是发展新手。请帮我解决这个问题。
lbl_bal_total.value = Numbers(lbl_bal_total.innerHTML) + Numbers(lbl_bal_others.value);
//lbl_bal_total.value = 1568 + .25; // Error lbl_bal_total value is NaN
lbl_bal_total.innerHTML = Math.round(lbl_bal_total.value);
答案 0 :(得分:1)
试试这个:
lbl_bal_total.innerHTML = Math.round(parseFloat(lbl_bal_total.innerHTML) + parseFloat(lbl_bal_others.value));
答案 1 :(得分:0)
var num = parseFloat(lbl_bal_total.innerHTML) + parseFloat(lbl_bal_others.value);
lbl_bal_total.innerHTML = Math.round(num);
答案 2 :(得分:0)
试试这个。数据类型为Number
而非Numbers
lbl_bal_total.value = Number(lbl_bal_total.innerHTML) + Number(lbl_bal_others.value);
//lbl_bal_total.value = 1568 + .25; // Error lbl_bal_total value is NaN
lbl_bal_total.innerHTML = Math.round(lbl_bal_total.value);
如果您不确定lbl_bal_total.innerHTML
和lbl_bal_others.value
的值,则可以使用isNaN