我在 jsp 中有一个表,它有 3 列 - num1、num2、sum
<table>
<tr>
<td>
Number1
</td>
</tr>
<tr>
<td>
Number2
</td>
</tr>
<tr>
<td>
Sum
</td>
</tr>
<s:iterator value="transactionList" var="row" status="status" >
<tr>
<td>
<s:textfield name = "num1" id="num1" onblur="fnSum();" />
</td>
<td>
<s:textfield name = "num2" id="num2" onblur="fnSum();" readonly="true" />
</td>
<td>
<s:textfield name = "sum" id="sum" />
</td>
</tr>
</s:iterator>
<script type="text/javascript">
function fnSum()
{
var num1 = parseInt(document.getElementById("num1").value);
var num2 = parseInt(document.getElementById("num2").value);
var total = num1 + num2;
document.getElementById("sum").value = total;
}
</script>
我想自动显示每一行的总和。上面的代码仅适用于第一行,但不适用于其他行。我不知道该怎么做。提前致谢