2012-02-24 154 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/