2015-03-02 72 views
0

如何possibily知道從餐桌的全產品總數量的總和,另外,如何自動給它編號像1,2,3項數量總數量與jQuery計算插件

任何意見之前,可以理解的

小提琴這裏>>

<table width="500"> 
       <col style="width: 50px;" /> 
       <col /> 
       <col style="width: 60px;" /> 
       <col style="width: 110px;" /> 
       <tr> 
        <th> 
         No # 
        </th> 
        <th> 
         Qty 
        </th> 
        <th align="left"> 
         Product 
        </th> 
        <th> 
         Price 
        </th> 
        <th> 
         Total 
        </th> 
       </tr> 
       <tr> 
        <td>?</td> 
        <td align="center"> 
         <input type="text" name="qty_item_1" id="qty_item_1" value="1" size="2" /> 
        </td> 
        <td> 
         <a href="http://www.packtpub.com/jQuery/book">Learning jQuery</a> 
        </td> 
        <td align="center" id="price_item_1"> 
         $39.99 
        </td> 
        <td align="center" id="total_item_1"> 
         $39.99 
        </td> 
       </tr> 
       <tr> 
        <td>?</td> 
        <td align="center"> 
         <input type="text" name="qty_item_2" id="qty_item_2" value="1" size="2" /> 
        </td> 
        <td> 
         <a href="http://jquery.com/">jQuery Donation</a> 
        </td> 
        <td align="center" id="price_item_2"> 
         $14.99 
        </td> 
        <td align="center" id="total_item_2"> 
         $14.99 
        </td> 
       </tr> 
       <tr> 
        <td>Total QTY</td> 
        <td>?</td> 

        <td colspan="3" align="right"> 
         <strong>Grand Total:</strong> 
        </td> 
        <td align="center" id="grandTotal"> 
        </td> 
       </tr> 
      </table> 

感謝

熱烈

回答

0

recalc功能試試這個:

var qtyTotals = 0; 
$("input[name^=qty_item_]").each(function() { 
    qtyTotals += parseInt($(this).val(), 10); 
}); 
$("#qtyTotal").text(qtyTotals); 

小提琴這裏http://jsfiddle.net/0e87jvor/2/