gpt4 book ai didi

javascript - 添加,使用Javascript函数添加多个文本框

转载 作者:行者123 更新时间:2023-12-03 12:13:32 24 4
gpt4 key购买 nike

我遇到这个问题,我添加了 8 个文本框,它工作正常,但是当我添加更多文本框(如 16 个文本框)时,它不会添加最后一个文本框。有人遇到过这个问题吗?提前致谢。

Live Link: JAVASCRIPT.

function sum() {

var basicpay = document.getElementById('basicpay').value;
var overtime = document.getElementById('overtime').value;
var regularholiday = document.getElementById('regularholiday').value;
var specialholiday = document.getElementById('specialholiday').value;
var allowanceday = document.getElementById('allowanceday').value;
var others = document.getElementById('others').value;
var grosspay = document.getElementById('grosspay').value;
var monthpay13 = document.getElementById('monthpay13').value;
var absent = document.getElementById('absent').value;
var tardiness = document.getElementById('tardiness').value;
var sss = document.getElementById('sss').value;
var pagibig = document.getElementById('pagibig').value;
var philhealth = document.getElementById('philhealth').value;
var cashadvances = document.getElementById('cashadvances').value;
var withholdingtax = document.getElementById('withholdingtax').value;
var others = document.getElementById('others').value;



var result =

parseInt(basicpay) +
parseInt(overtime) +
parseInt(regularholiday) +
parseInt(specialholiday) +
parseInt(allowanceday) +
parseInt(others) +
parseInt(grosspay) +
parseInt(absent) +
parseInt(tardiness) +
parseInt(sss) +
parseInt(pagibig) +
parseInt(philhealth) +
parseInt(cashadvances) +
parseInt(withholdingtax) +
parseInt(others) +
parseInt(monthpay13);

if (!isNaN(result)) {
document.getElementById('totalincome').value = result;
}
}

最佳答案

问题是您使用相同的 ID others对于字段 6 和字段 16。给它们不同的 ID

16.<input type="text" id="others1" Placeholder="More others"  onkeyup="sum();" /><br>

并更改 JS:

var others1 = var others = document.getElementById('others1').value;

var result =

parseInt(basicpay) +
parseInt(overtime) +
parseInt(regularholiday) +
parseInt(specialholiday) +
parseInt(allowanceday) +
parseInt(others) +
parseInt(grosspay) +
parseInt(absent) +
parseInt(tardiness) +
parseInt(sss) +
parseInt(pagibig) +
parseInt(philhealth) +
parseInt(cashadvances) +
parseInt(withholdingtax) +
parseInt(others1) +
parseInt(monthpay13);

关于javascript - 添加,使用Javascript函数添加多个文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24838747/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com