【发布时间】:2016-06-03 14:35:13
【问题描述】:
我有一份产品订购单,有不同尺寸可供选择。 因此,对于每种产品,每种尺寸都有一个输入,总和位于行尾。 我实际上有大约 500 行。
<table>
<tr>
<th>Product</th>
<th>Size 1</th>
<th>Size 2</th>
<th>Size 3</th>
<th>TOTAL</th>
</tr>
<tr>
<td>A</td>
<td><input type="text" class="productA"></td>
<td><input type="text" class="productA"></td>
<td><input type="text" class="productA"></td>
<td></td>
</tr>
<tr>
<td>B</td>
<td><input type="text" class="productB"></td>
<td><input type="text" class="productB"></td>
<td><input type="text" class="productB"></td>
<td></td>
</tr>
<tr>
<td>C</td>
<td><input type="text" class="productC"></td>
<td><input type="text" class="productC"></td>
<td><input type="text" class="productC"></td>
<td></td>
</tr>
</table>
我尝试了几种方法,但它从来不想工作。我只成功地一次计算了所有输入,但不仅仅是单独计算了一行。
我想在每次输入变化时计算最后一个td中每一行的总和。
有人知道我该如何解决这个问题吗?
【问题讨论】:
-
我们不会为你写的。请张贴您的几种方法之一,以便我们帮助您了解哪里出错了。看起来它应该是一个非常简单的
$("tr").each()循环。 -
在里面你会使用
$(this).find("input").each()。
标签: javascript jquery