jquery实现 购物车 信息 级联改变

来源:互联网 发布:jsp php asp.net 编辑:程序博客网 时间:2024/06/06 04:41
Html代码  收藏代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
  2. <html xmlns="http://www.w3.org/1999/xhtml">   
  3. <head>   
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />   
  5. <title>jQuery</title>   
  6. <link rel="stylesheet" type="text/css" href="style.css" />   
  7. <script src="http://www.google.com/jsapi" type="text/javascript"></script>   
  8. <script type="text/javascript">   
  9. google.load("jquery", "1.2.6");   
  10. </script>   
  11. <script type="text/javascript" src="order.js"></script>   
  12. </head>   
  13. <body>   
  14. <table id="order-table">   
  15. <tr>   
  16. <th>Product Name</th>   
  17. <th>Quantity</th>   
  18. <th>X</th>   
  19. <th>Unit Price</th>   
  20. <th>=</th>   
  21. <th style="text-align: right;">Totals</th>   
  22. </tr>   
  23. <tr class="odd">   
  24. <td class="product-title">www.corange.cn<em></em></td>   
  25. <td class="num-pallets">   
  26. <input type="text" class="num-pallets-input" id="turface-pro-league-num-pallets" >   
  27. </input>   
  28. </td>   
  29. <td class="times">X</td>   
  30. <td class="price-per-pallet">$<span>340</span></td>   
  31. <td class="equals">=</td>   
  32. <td class="row-total">   
  33. <input type="text" class="row-total-input" id="turface-pro-league-row-total" disabled="disabled">   
  34. </input>   
  35. </td>   
  36. </tr>   
  37. <tr class="even">   
  38. <td class="product-title"><p>Turface&reg; Pro League Red - <em>Calcined Clay Top Dressinged</em></p>  
  39.   <p>&nbsp;</p></td>   
  40. <td class="num-pallets">   
  41. <input type="text" class="num-pallets-input" id="turface-pro-league-red-num-pallets">   
  42. </input>   
  43. </td>   
  44. <td class="times">X</td>   
  45. <td class="price-per-pallet">$<span>455</span></td>   
  46. <td class="equals">=</td>   
  47. <td class="row-total">   
  48. <input type="text" class="row-total-input" id="turface-pro-league-red-row-total" disabled="disabled">   
  49. </input>   
  50. </td>   
  51. </tr>   
  52. <tr class="odd">   
  53. <td class="product-title">Turface&reg; Quick Dry - <em>Calcined Clay Moisture Absorbent</em></td>   
  54. <td class="num-pallets">   
  55. <input type="text" class="num-pallets-input" id="turface-quick-dry-num-pallets" >   
  56. </input>   
  57. </td>   
  58. <td class="times">X</td>   
  59. <td class="price-per-pallet">$<span>100</span></td>   
  60. <td class="equals">=</td>   
  61. <td class="row-total">   
  62. <input type="text" class="row-total-input" id="turface-quick-dry-row-total" disabled="disabled">   
  63. </input>   
  64. </td>   
  65. </tr>   
  66. <tr class="even">   
  67. <td class="product-title">Turface&reg; Mound Clay Red - <em>Virgin Red Clay</em></td>   
  68. <td class="num-pallets">   
  69. <input type="text" class="num-pallets-input" id="turface-mound-clay-red-num-pallets">   
  70. </input>   
  71. </td>   
  72. <td class="times">X</td>   
  73. <td class="price-per-pallet">$<span>40</span></td>   
  74. <td class="equals">=</td>   
  75. <td class="row-total">   
  76. <input type="text" class="row-total-input" id="turface-mound-clay-red-row-total" disabled="disabled">   
  77. </input>   
  78. </td>   
  79. </tr>   
  80. <tr class="odd">   
  81. <td class="product-title">Red Infield Conditioner - <em>Vitrified Clay Top Dressing</em></td>   
  82. <td class="num-pallets">   
  83. <input type="text" class="num-pallets-input" id="diamond-pro-red-num-pallets" >   
  84. </input>   
  85. </td>   
  86. <td class="times">X</td>   
  87. <td class="price-per-pallet">$<span>35</span></td>   
  88. <td class="equals">=</td>   
  89. <td class="row-total">   
  90. <input type="text" class="row-total-input" id="diamond-pro-red-row-total" disabled="disabled">   
  91. </input>   
  92. </td>   
  93. </tr>   
  94. <tr class="even">   
  95. <td class="product-title">Drying Agent - <em>Calcined Clay Moisture Absorbent</em></td>   
  96. <td class="num-pallets">   
  97. <input type="text" class="num-pallets-input" id="diamond-pro-drying-agent-num-pallets">   
  98. </input>   
  99. </td>   
  100. <td class="times">X</td>   
  101. <td class="price-per-pallet">$<span>340</span></td>   
  102. <td class="equals">=</td>   
  103. <td class="row-total">   
  104. <input type="text" class="row-total-input" id="diamond-pro-drying-agent-row-total" disabled="disabled">   
  105. </input>   
  106. </td>   
  107. </tr>   
  108. <tr class="odd">   
  109. <td class="product-title">Professional - <em>Calcined Clay Top Dressing</em></td>   
  110. <td class="num-pallets">   
  111. <input type="text" class="num-pallets-input" id="diamond-pro-professional-num-pallets" >   
  112. </input>   
  113. </td>   
  114. <td class="times">X</td>   
  115. <td class="price-per-pallet">$<span>75</span></td>   
  116. <td class="equals">=</td>   
  117. <td class="row-total">   
  118. <input type="text" class="row-total-input" id="diamond-pro-professional-row-total" disabled="disabled">   
  119. </input>   
  120. </td>   
  121. </tr>   
  122. <tr class="even">   
  123. <td class="product-title">Top Dressing - <em>Calcined Clay Soil Conditioner</em></td>   
  124. <td class="num-pallets">   
  125. <input type="text" class="num-pallets-input" id="diamond-pro-top-dressing-num-pallets">   
  126. </input>   
  127. </td>   
  128. <td class="times">X</td>   
  129. <td class="price-per-pallet">$<span>30</span></td>   
  130. <td class="equals">=</td>   
  131. <td class="row-total">   
  132. <input type="text" class="row-total-input" id="diamond-pro-top-dressing-row-total" disabled="disabled">   
  133. </input>   
  134. </td>   
  135. </tr>   
  136. <tr>   
  137. <td colspan="6" style="text-align: right;"> Product SUBTOTAL:   
  138. <input type="text" class="total-box" id="product-subtotal" disabled="disabled">   
  139. </input>   
  140. </td>   
  141. </tr>   
  142. </table>   
  143. </body>   
  144. </html>   

 

Java代码  收藏代码
  1. function IsNumeric(sText)   
  2.   
  3. {   
  4. var ValidChars = "0123456789.";   
  5. var IsNumber=true;   
  6. var Char;   
  7.   
  8.   
  9. for (i = 0; i < sText.length && IsNumber == true; i++)   
  10. {   
  11. Char = sText.charAt(i);   
  12. if (ValidChars.indexOf(Char) == -1)   
  13. {   
  14. IsNumber = false;   
  15. }   
  16. }   
  17. return IsNumber;   
  18.   
  19. };   
  20.   
  21. function calcProdSubTotal() {   
  22.   
  23. var prodSubTotal = 0;   
  24.   
  25. $(".row-total-input").each(function(){   
  26.   
  27. var valString = $(this).val() || 0;   
  28.   
  29. prodSubTotal += parseInt(valString);   
  30.   
  31. });   
  32.   
  33. $("#product-subtotal").val(prodSubTotal);   
  34.   
  35. };   
  36.   
  37. function calcTotalPallets() {   
  38.   
  39. var totalPallets = 0;   
  40.   
  41. $(".num-pallets-input").each(function() {   
  42.   
  43. var thisValue = $(this).val();   
  44.   
  45. if ( (IsNumeric(thisValue)) && (thisValue != '') ) {   
  46.   
  47. totalPallets += parseInt(thisValue);   
  48.   
  49. };   
  50.   
  51. });   
  52.   
  53. $("#total-pallets-input").val(totalPallets);   
  54.   
  55. };   
  56.   
  57. function calcShippingTotal() {   
  58.   
  59. var totalPallets = $("#total-pallets-input").val() || 0;   
  60. var shippingRate = $("#shipping-rate").text() || 0;   
  61. var shippingTotal = totalPallets * shippingRate;   
  62.   
  63. $("#shipping-subtotal").val(shippingTotal);   
  64.   
  65. };   
  66.   
  67. function calcOrderTotal() {   
  68.   
  69. var orderTotal = 0;   
  70.   
  71. var productSubtotal = $("#product-subtotal").val() || 0;   
  72. var shippingSubtotal = $("#shipping-subtotal").val() || 0;   
  73.   
  74. var orderTotal = parseInt(productSubtotal) + parseInt(shippingSubtotal);   
  75. var orderTotalNice = "$" + orderTotal;   
  76.   
  77. $("#order-total").val(orderTotalNice);   
  78.   
  79. };   
  80.   
  81. $(function(){   
  82.   
  83. $('.num-pallets-input').blur(function(){   
  84.   
  85. var $this = $(this);   
  86.   
  87. var numPallets = $this.val();   
  88. var multiplier = $this   
  89. .parent().parent()   
  90. .find("td.price-per-pallet span")   
  91. .text();   
  92.   
  93. if ( (IsNumeric(numPallets)) && (numPallets != '') ) {   
  94.   
  95. var rowTotal = numPallets * multiplier;   
  96.   
  97. $this   
  98. .css("background-color""white")   
  99. .parent().parent()   
  100. .find("td.row-total input")   
  101. .val(rowTotal);   
  102.   
  103. else {   
  104.   
  105. $this.css("background-color""#ffdcdc");   
  106.   
  107. };   
  108.   
  109. calcProdSubTotal();   
  110. calcTotalPallets();   
  111. calcShippingTotal();   
  112. calcOrderTotal();   
  113.   
  114. });   
  115.   
  116. });   

 

  • myorder.zip (2.5 KB)
原创粉丝点击