这是我在所有文本框中添加时的代码,它工作正常,但在删除数字后它显示 NaN:
function sumVal()
{
var total = 0;
var coll = document.getElementsByTagName("input")
for ( var i = 0; i<coll.length; i++)
{
var ele = coll[i];
total += parseInt(ele.value);
}
var Display = document.getElementById("Display");
Display.innerHTML = total;
}
<input onkeyup="sumVal()" />
<input onkeyup="sumVal()" />
<input onkeyup="sumVal()" />