【发布时间】:2010-08-19 06:35:51
【问题描述】:
我在订单页面上有一个表格,我需要在用户更改数量时更新行总计。我有总计工作,但无法获得行总计,因为我无法弄清楚如何定位正确的元素。
表单是由 cms 生成的,因此最终会被包裹在许多无关的 div 等中,...这是每个行项目的简化版本:
<input type="text" class="text cart_qty" id="Form_OrderForm_Product-1065-qty" name="Product[1065][qty]" value="1" />
<input type="text" class="text prod_id" id="Form_OrderForm_prod_1065" name="prod_1065" value="1065" />
<input class="hidden" type="hidden" id="Form_OrderForm_hidden_1065" name="hidden_1065" value="1.45" />
<span id='Product_1065_Line' class='cart_price_line'>1.45</span>
所以基本上,只要 .cart_qty 输入字段发生更改,.cart_price_line 就需要更新。
我的总数是这样的:
$('.cart_qty').keyup(function(){
var $thetotal=0;
$('input.cart_qty').each(function(index) {
$theqty=$(this).val();
$thenextindex=$("input").index(this) + 2;
$theprice=$("input:eq("+$thenextindex+")").val();
$thelinetotal=$theqty * $theprice;
$thetotal=$thetotal + $thelinetotal;
});
$("#total_price_curr").html($thetotal).formatCurrency();
$("#Form_OrderForm_totalHidden").val($thetotal);
});
它可以计算订单项,但我不知道如何在 $("input.cart_qty").each(...) 函数中定位 span.cart_price_line。
任何帮助将不胜感激
【问题讨论】: