【发布时间】:2015-06-19 06:20:18
【问题描述】:
我有以下代码:
{% 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 的值?我必须收集每种产品的数量。你能帮我吗?提前谢谢
【问题讨论】:
标签: javascript jquery html ajax onkeyup