2012-02-24 216 views
0

:插件 主页:LinkJQuery:计算插件不计算总价

:JavaScript的

$("[id^=total_price_ht]").calc(
    // the equation to use for the calculation 
    "qty * price", 
    { 
     qty: $("[id^=unit_quantity_]"), 
     price: $("[id^=unit_price_ht_]") 
    }, 
    function (s){ 
     // return the number as a dollar amount 
     return "$" + s.toFixed(2); 
    } 
); 

:HTML

<tr id="lines[0]"> 
    <td> 
    <input id="0" type="checkbox" class="hiddenCheckbox"> 
    <label for="0" class="prettyCheckbox checkbox list"><span class="holderWrap" style="width: 18px; height: 19px; "><span class="holder" style="width: 18px; "></span></span></label> 
    </td> 
    <td> 
    <input class="required" name="lines[0][title]" placeholder="Title" type="text"> 
    </td> 
    <td> 
    <input name="lines[0][description]" placeholder="Description" type="text"> 
    </td> 
    <td> 
    <input class="required" id="unit_quantity_0" name="lines[0][quantity]" placeholder="Quantité" type="text" value="0,00"> 
    </td> 
    <td> 
    <input class="required" id="unit_price_ht_0" name="lines[0][unit_price_ht]" placeholder="Prix unit. HT" type="text" value="0,00"> 
    </td> 
    <td class="price" id="total_price_ht_0">$0.00</td> 
</tr> 

一旦页面加载,我可以看到“$ 0.00" 在total_price_ht领域,但它的价值没有得到时变我更改数量或价格

我在做什么错?谢谢。

+0

你能发布生成的HTML? – 2012-02-24 14:54:30

+0

@AndrewWhitaker我发布了生成的HTML。谢谢。 – Laura 2012-02-24 14:59:22

+0

谢谢 - 这是你使用的插件吗? http://www.pengoworks.com/workshop/jquery/calculation/calculation.plugin.htm – 2012-02-24 15:00:20

回答

0

我想你需要要重新计算总的每次调用calc插件:

$("[id^='unit_quantity_'], [id^='unit_price_ht_']").keyup(recalc); 


function recalc() { 

    $("[id^='total_price_ht']").calc(
    // the equation to use for the calculation 
    "qty * price", { 
     bind: "keyup", 
     qty: $("[id^='unit_quantity_']"), 
     price: $("[id^='unit_price_ht_']") 
    }, function(s) { 
     // return the number as a dollar amount 
     return "$" + s.toFixed(2); 
    }); 
} 

recalc(); 

例子:http://jsfiddle.net/upEZW/