jquery 无刷新添加/删除 input行 实时计算购物车价格

jquery 无刷新添加/删除 input行 实时计算购物车价格

jquery 未来事件插件jq_Live_Extension.js

jquery 无刷新添加/删除 input行 实时计算购物车价格

 

 

XML/HTML Code
  1. <script>
  2.     $(document).ready(function(){
  3.        //<tr/>居中
  4.         $(“#tab tr”).attr(“align”,”center”);
  5.         //增加<tr/>
  6.        $(“#but”).click(function(){
  7.             var _len = $(“#tab tr”).length;
  8.             $(“#tab”).append(“<tr id=”+_len+” align=’center’>”
  9.                                +”<td>”+_len+”</td>”
  10.                                +”<td align=’left’><input type=” name=’product_id[]’ value=\”\” onFocus=\”this.value=”\”/ class=\”order_form_product_description\” id=’product_id”+_len+”‘></td>”
  11.                                +”<td><input type=’text’ name=’quantity[]’ id=’quantity”+_len+”‘ class=’num-pallets-input’ ></td>”
  12.                                +”<td><input type=’text’ name=’price[]’ id=’price”+_len+”‘ class=’price-per-pallet’/></td>”
  13.                                +”<td class=’row-total’><span id=’thistotal”+_len+”‘ class=’row-total-input’></span></td>”
  14.                                +”<td><a href=’javascript:void(0)’ onclick=\’deltr(“+_len+”)\’><img src=’form_del_icon.gif’></a></td>”
  15.                            +”</tr>”);
  16.         })
  17.    })
  18.     //删除<tr/>
  19.     var deltr =function(index)
  20.     {
  21.        var _len = $(“#tab tr”).length;
  22.         $(“tr[id='”+index+”‘]”).remove();//删除当前行
  23.        for(var i=index+1,j=_len;i<j;i++)
  24.        {
  25.             var nextTxtVal = $(“#quantity”+i).val();
  26.             var nextPriceVal= $(“#price”+i).val();
  27.             var nextproduct_idVal= $(“#product_id”+i).val();
  28.             var nextthistotalVal= $(“#thistotal”+i).text();
  29.             //alert (nextthistotalVal);
  30.           $(“tr[id=\'”+i+”\’]”)
  31.                 .replaceWith(“<tr id=”+(i-1)+” align=’center’>”
  32.                                +”<td>”+(i-1)+”</td>”
  33.                                +”<td align=’left’><input type=’text’ name=’product_id[]’ value='”+nextproduct_idVal+”‘ class=\”order_form_product_description\” id=’product_id”+(i-1)+”‘></td>”
  34.                                 +”<td><input type=’text’ name=’quantity[]’ value='”+nextTxtVal+”‘ id=’quantity”+(i-1)+”‘ class=’num-pallets-input’/></td>”
  35.                                 +”<td><input type=’text’ name=’price[]’ class=’price-per-pallet’ name=’price”+(i-1)+”‘ value='”+nextPriceVal+”‘ /></td>”
  36.                                 +”<td class=’row-total’><span class=’row-total-input’>”+nextthistotalVal+”</span></td>”
  37.                                +”<td><a href=’javascript:void(0)’ onclick=\’deltr(“+(i-1)+”)\’><img src=’form_del_icon.gif’></a></td>”
  38.                            +”</tr>”);
  39.          }
  40.          calcProdSubTotal();
  41.  }
  42. </script>
  43. <body>
  44.    <table id=”tab” border=”0″ width=”500″ align=”center” style=”margin-top:20px”>
  45.         <tr>
  46.             <td></td>
  47.             <td align=”left”><span class=”red”>*</span>Product Description</td>
  48.             <td><span class=”red”>*</span>Quantity</td>
  49.             <td><span class=”red”>*</span>Unit Price (USD)</td>
  50.             <td>Amount(USD)</td>
  51.             <td></td>
  52.      </tr>
  53.      <tr>
  54.      <td>1</td>
  55.      <td align=”left”><input type=”” name=”product_id[]” value=”” onFocus=”this.value=”” class=”order_form_product_description” /></td>
  56.      <td><input type=”text” class=”num-pallets-input” name=”quantity[]” onKeyPress=”if ((event.keyCode<48 || event.keyCode>57)) event.returnValue=false”/></td>
  57.      <td><input type=”” class=”price-per-pallet” name=”price[]” onKeyPress=”if (event.keyCode!=46 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false”></td>
  58.      <td class=”row-total”><span class=”row-total-input”></span></td>
  59.      <td></td>
  60.      </tr>
  61.    </table>
  62.     <div style=”margin-left:205px;margin-top:20px”>
  63.        <img src=”add_more_products.gif” id=”but” style=”cursor:pointer”/>
  64.     </div>
  65.     <div style=” float:right; padding-right:50px; font-weight:bold”>Total:<span class=”red”>US$<span id=”product-subtotal”>0</span></span><input type=”hidden” name=”product-subtotal” /></div>
  66. </div>

标签