我想通过将单个行的输入相乘来计算每一行的总价格,然后最后通过使用 JQuery 将 Total 列的所有总值相加来计算总计。当我输入值时,我只会让第一行显示总计。任何帮助将不胜感激。
<script type="text/C#" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$(".txtMult").each(function () {
$(this).keyup(function () {
multInputs();
});
});
});
function multInputs() {
var mult = 0;
$(".txtMult").each(function () {
var $val1 = $('#val1').val();
var $val2 = $('#val2').val();
var $total = ($val1 * 1) * ($val2 * 1)
$('#multTotal').text($total);
});
}
</script>
@using (@Html.BeginForm())
{
<table>
<tr>
<th>
Quanity
</th>
<th>
Unit Price
</th>
<th>
Total
</th>
</tr>
@for (int i=0; i < 5; i++)
{
<tr>
<td>
<input class ="txtMult" name="txtEmmail" id="val1" />
</td>
<td>
<input class ="txtMult" name="txtEmmail" id="val2"/>
</td>
<td>
<span id="multTotal">0.00</span>
</td>
</tr>
}
<tr>
<td colspan="3" align="right">
Grand Total# <span id="grandTotal">0.00</span>
</td>
</tr>
</table>
}