我有以下代碼:更新上的文本字段的KEYUP值
{% for product in app.session.get('aBasket') %}
<input id="product_quantity_{{ product['product_id'] }}" class="form-control quantity" type="text" value="{{ product['product_quantity'] }}" name="" onkeyup="calculatePrice({{ product['product_price'] }},{{ product['product_id'] }})">
<span id="total_price_{{ product['product_id'] }}">{{ product['product_quantity'] * product['product_price'] }}</span>
{%endfor}
<div id="total_price_basket">TOTAL:0</div>
我的js函數:
<script type="application/javascript">
function calculatePrice(price, product_id) {
var x = document.getElementById("product_quantity_"+product_id);
var total_price = price * x.value;
$("#total_price_"+product_id).html(total_price);
$("#total_price_basket").html();
}
</script>
所以,價格爲它工作正常的所有產品,問題是如何更改div> total_price_basket onkeyup的值?我必須收集每個產品的數量。你能幫我嗎? Thx
不計算t他total_price_baket – TanGio
它應該,檢查演示。 – dfsq
Bizzare但不適合我:(爲每個產品的價格計算,但總價格沒有 – TanGio