【发布时间】:2017-02-01 18:39:52
【问题描述】:
我有这个代码,但不能正常工作。
这个想法是每个输入都有一个值,并且根据您是点击向上还是向下,从总价格中求和或减去它的值。
现在只是疯狂地添加和添加。
非常感谢。
JS:
$( document ).ready(function() {
$(".quantity").each(function(){
$(this).change(function(){
var quantity = ($(this).val());
var ammount = ($(this).attr("data-price"));
var price = $(this).closest(".bookSection").find(".item_price").html();
var subtotal = ammount * quantity;
var total = parseInt(subtotal) + parseInt(price);
$(this).closest(".bookSection").find(".item_price").html(total);
});
});
});
【问题讨论】:
-
每次数量变化时,您都会将小计添加到价格中。您永远不会从价格中减去任何东西。
标签: javascript jquery input