根据此处的帖子JQuery multiply input values of table rows,我使用相同的表单字段名称并添加了Tax字段和Discount字段。
<tr class="txtMult">
<td>
<input name="txtEmmail" class="val1" />
</td>
<td>
<input name="txtEmmail" class="val2"/>
</td>
<td>
<span class="multTotal">0.00</span>
</td>
</tr>
<tr class="txtMult">
<td>
<input name="txttax" class="val1" />%
</td>
<td>
</td>
<td>
<span class="multTax">0.00</span>
</td>
</tr>
此税需要倍增,就像我输入10(%)
一样var $tax = ($val1 * 1) * ($total * 1)/100;
$('.multTax', this).text($tax);
然后将其作为税额 我将txttax类值更改为val3并添加了如上所述的jquery
再次,我需要减去折扣,我尝试了所有可能的方法,但没有运气。
这是功能(编辑)
$(document).ready(function () {
$(".txtMult input").keyup(multInputs);
function multInputs() {
var mult = 0;
$("tr.txtMult").each(function () {
var $val1 = $('.val1', this).val();
var $val2 = $('.val2', this).val();
var $val3 = $('.val3', this).val();
var $total = ($val1 * 1) * ($val2 * 1);
var $tax = ($val1 * 1) * ($total * 1)/100;
$('.multTotal', this).text($total);
$('.multTax', this).text($tax);
mult += $total;
});
$("#grandTotal").text(mult);
}
});
请指教。 (花了一整天)
答案 0 :(得分:2)
HTML
<table>
<tr class="txtMult">
<td>
<input name="txtEmmail" class="val1" />
</td>
<td>
<input name="txtEmmail" class="val2"/>
</td>
<td>
<span class="multTotal">0.00</span>
</td>
</tr>
<tr class="txtMult odd">
<td>
<input name="txttax" class="val3" />%
</td>
<td>
</td>
<td>
<span class="multTax">0.00</span>
</td>
</tr>
</table>
<span id="grandTotal"></span>
JS
$(document).ready(function () {
$("input").keyup(multInputs);
function multInputs() {
var mult = 0;
$("tr.txtMult").not('.odd').each(function () {
var $val1 = $('.val1', this).val();
var $val2 = $('.val2', this).val();
var $val3 = $('.val3', $(this).next()).val();
var $total = $val1 * $val2;
var $tax = $val3 * ($total / 100);
$('.multTotal', this).text($total);
$('.multTax', $(this).next()).text($tax);
mult += $total - $tax;
});
$("#grandTotal").text(mult);
}
});