0
我有一个简单的开发票页面,所以我可以为我的客户开具发票,但是当我要执行数量和价格的乘法时,行总数不会被添加。这是我的jQuery到目前为止。jQuery在多个元素上的数学运算
$(":input").bind('keypress keydown keyup change', function(){
var price = parseFloat($(this).closest('.tr').find('.price').val(),10),
var qty = parseFloat($(this).closest('tr').find('.quantity').val(),10);
var v = '';
if(!isNaN(price) && !isNaN(qty)) {
v = price * qty;
}
$(this).closest('tr').find('.rowtotal').val(v.toString());
});
这是我的HTML:
<table>
<tr>
<td>1</td>
<td><input name="item_name[]"class="form-control"></td>
<td><input name="item_description[]"class="form-control"></td>
<td><input name="item_price[]"class="form-control price"></td>
<td><input name="item_quantity[]"class="form-control quantity"></td>
<td><span class="rowtotal">0.00</span></td>
</tr>
<tr>
<td>2</td>
<td><input name="item_name[]"class="form-control"></td>
<td><input name="item_description[]"class="form-control"></td>
<td><input name="item_price[]"class="form-control price"></td>
<td><input name="item_quantity[]"class="form-control quantity"></td>
<td><span class="rowtotal">0.00</span></td>
</tr>
</table>
现在我的网页上,就说明没有错误,同时审查控制台,但不执行的操作,我创建了下面这篇文章“Automatically updating input field with math using jquery? “
任何帮助表示赞赏。
TIA
另外,由于'.rowtotal'不是输入元件,'.VAL()'是行不通的。使用'.text()'应该,并且OP不必将'v'转换为字符串:) – Terry
@Terry我到了那里。也没有parseFloat超载 - 更新答案:) – CodingIntrigue
谢谢你们,让我来实现它。 –