【发布时间】:2014-08-02 13:22:00
【问题描述】:
我想写一个 jQuery 脚本,它可以总结给定形式的一些值。
表格如下所示:
<form>
Product 1
<input type="text" name="quantity[]" value="" class="quantity" placeholder="Quantity" />
<input type="text" name="price_per_unit[]" value="" class="price_per_unit" placeholder="Price per unit" />
Product 2
<input type="text" name="quantity[]" value="" class="quantity" placeholder="Quantity" />
<input type="text" name="price_per_unit[]" value="" class="price_per_unit" placeholder="Price per unit" />
Product 3
<input type="text" name="quantity[]" value="" class="quantity" placeholder="Quantity" />
<input type="text" name="price_per_unit[]" value="" class="price_per_unit" placeholder="Price per unit" />
[...]
Product n
<input type="text" name="quantity[]" value="" class="quantity" placeholder="Quantity" />
<input type="text" name="price_per_unit[]" value="" class="price_per_unit" placeholder="Price per unit" />
<input type="text" name="total_order" id="total_order" value="" readonly="readonly" />
</form>
如果用户输入值“2”作为数量,“10”作为“单价”,则总订单为“20”。
我只想在“数量”和“单价”这对填写时触发求和操作。
此外,如果用户输入了不止一种产品的数量和价格,则总订单必须是它们的总和。
稍后编辑 抱歉,到目前为止我忘了发布我的 jQuery 代码:
$(document).ready(function(){
var total = 0;
$('input .quantity').each(function() {
$('input .price_per_unit').each(function() {
});
});
});
【问题讨论】:
-
好吧,你想要那个。如果你付钱给他,有人会为你编码。 (包括我)但是在 Stackoverflow 提问之前,您应该先尝试一下。