为什么我的功能不起作用?我希望输入字段中的数字自动添加到“下部总计”框中。
3 of a kind: <input type="text" name="qtyB">
<br>
4 of a kind: <input type="text" name="qtyB">
<br>
Full House: <input type="text" name="qtyB">
<br>
Little Straight: <input type="text" name="qtyB">
<br>
Lg. Straight: <input type="text" name="qtyB">
<br>
<b>Yahtzeebeshy:</b> <input type="text" name="qtyB">
<br>
Chance: <input type="text" name="qtyB">
<br>
Lower Section Total: <input type="text" id="LowerSectionTotal">
function findTotalB() {
var arrB = document.getElementsByName('qtyB');
var totB = 0;
for (var i = 0; i < arrB.length; i++) {
if (parseInt(arrB[i].value))
totB += parseInt(arrB[i].value);
}
document.getElementById('LowerSectionTotal').value = totB;
}
最佳答案
function findTotalB() {
var arrB = document.getElementsByName('qtyB');
var totB = 0;
for (var i = 0; i < arrB.length; i++) {
var value = 0 ;
try {
value = parseInt(arrB[i].value.trim());
} catch ( e ) {
}
totB += value ;
}
document.getElementById('LowerSectionTotal').value = totB;
}
关于javascript - 我写的这个函数怎么了?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45626462/