爲什麼我的功能不起作用?我希望放入輸入字段的數字自動添加到「下部分總計」框中。我寫的這個函數有什麼問題?
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;
}
表示不會調用函數的代碼。 – nnnnnn
這是接近它的另一種方式:https://jsfiddle.net/sheriffderek/h2f2r45j/ – sheriffderek