gpt4 book ai didi

javascript - 如何计算多行的总和?

转载 作者:太空宇宙 更新时间:2023-11-04 15:14:24 24 4
gpt4 key购买 nike

<分区>

您好,我正在使用 this table计算总和。我需要做的是从 r1、r2、r3 下面的文本框中获取输入,然后从下面的框中计算总和例如:- totalcost= r1.value*5+r2.value*6+r3.value*5 像这样它必须发生在每一行值 onclick ....我该怎么做?

这里是我的代码:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function updatesum() {
var totalFields = document.input.time.length;
for(var i=0; i <= totalFields; i++){
document.input.total[i].value = ( document.input.time[i].value * document.input.cost[i].value);
}
return false;
}
</script>

<style>
input {
float: right;
}
</style>
</head>
<body>
<form name="input" action="#" method="post" onsubmit="return false;">
<table border="1">
<tr><th>Sl.no</th><th>id</th><th>title</th><th>R1<br><input type="text" name="cost" value=" "></th><th>R2<br><input type="text" name="cost" value=" "></th><th>R3<br><input type="text" name="cost" value=" "></th><th>Total Cost</th></tr>
<tr><td>1</td><td>1.1</td><td>task1</td><td><input type="text" name="time" value="5" disabled></td><td><input type="text" name="time" value="6" disabled></td><td><input type="text" name="time" value="5" disabled></td><td><input type="text" name="cost" value=" " disabled></td></tr>
<tr><td>2</td><td>1.2</td><td>task1</td><td><input type="text" name="time" value="7" disabled></td><td><input type="text" name="time" value="8" disabled></td><td><input type="text" name="time" value="2" disabled></td><td><input type="text" name="cost" value=" " disabled></td></tr>
<tr><td>3</td><td>1.4</td><td>task1</td><td><input type="text" name="time" value="9" disabled></td><td><input type="text" name="time" value="4" disabled></td><td><input type="text" name="time" value="7" disabled></td><td><input type="text" name="cost" value=" " disabled></td></tr>
<tr><td colspan="7"><input type="submit" value="submit" name="submit" onclick="updatesum()"></td></tr>
</table>
</form>
</body>
</html>

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