我有这个购物车结帐页面。 Screenshot of webpage
我需要计算价格的总和,并在下面的<div>
这是html:
<div class='row'>
<div class='col-md-2'>
<a href='#' remove_id='$pid' class='btn btn-danger remove'>
<span class='glyphicon glyphicon-trash'>
</span>
</a>
<a href='#' update_id='$pid' class='btn btn-success update'>
<span class='glyphicon glyphicon-ok-sign'>
</span>
</a>
</div>
<div class='col-md-2'>
<img src='assets/prod_images/$product_image' width='60px' height='60px'>
</div>
<div class='col-md-2'>$product_title</div>
<div class='col-md-2'>
<input class='form-control price' type='text' size='10px' pid='$pid' id='price-$pid' value='$product_price' disabled>
</div>
<div class='col-md-2'>
<input class='form-control qty' type='text' size='10px' pid='$pid' id='qty-$pid' value='$qty'>
</div>
<div class='col-md-2'>
<input class='value form-control price' type='text' size='10px' pid='$pid' id='amt-$pid' value='$total' disabled>
</div>
</div>
&#13;
答案 0 :(得分:0)
试试这个:
var total = 0;
$('input.price').each(function() {
total += parseFloat($(this).val());
});
$('input.total').val(total);
答案 1 :(得分:0)
基于html,这是一个将返回总价格的函数:
function getTotalPrice() {
var total = 0;
$.each($("input.price.value"), function(index, item) {
total += parseFloat($(item).val());
});
return total;
}
然后你可以在<div>
元素的html中设置总价格,例如像这样(你应该使用正确的选择器):
$("div").html(getTotalPrice());