This article shares the specific code for jQuery to realize the shopping cart settlement function for your reference. The specific content is as follows
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="js/jquery-1.8." ></script> <script> /*delete*/ $(function(){ $(".blue").bind("click",function(){ $(this).parent().parent().remove(); totalPrice(); }); /*When the mouse leaves the text box, get the current value and call the totalPrice() function for settlement*/ $(".shopping_product_list_5 input").bind("blur",function(){ var t = $(this).val(); totalPrice(); }); var allPrice = 0; var allReduce = 0; var allCount = 0; $("#myTableProduct tr").each(function(){ /*Cycle every line of the shopping cart list*/ var num = parseInt($(this).find(".shopping_product_list_5 input").val()); /*Get the quantity value in the text box*/ var price = parseFloat($(this).find(".shopping_product_list_4 label").text()); /* Get product price*/ var total = price * num; allPrice += total; /*Calculate the total price of all items*/ /*Get savings var reduce = parseFloat($(this).find(".shopping_product_list_3 label").text()) - parseFloat($(this).find(".shopping_product_list_4 label").text()); var reducePrice = reduce*num; allReduce +=reducePrice; /*Get points*/ var count = parseFloat($(this).find(".shopping_product_list_2 label").text()); allCount +=count; }); $("#product_total").text((2)); /*Fill in the calculation result, where two decimal places are retained using the toFixed() function*/ $("#product_save").text((2)); $("#product_integral").text((2)); }); function totalPrice(){ var allPrice = 0; var allReduce = 0; var allCount = 0; $("#myTableProduct tr").each(function(){ var num = parseInt($(this).find(".shopping_product_list_5 input").val()); var price = parseFloat($(this).find(".shopping_product_list_4 label").text()); var total = price * num; allPrice += total; var reduce = parseFloat($(this).find(".shopping_product_list_3 label").text()) - parseFloat($(this).find(".shopping_product_list_4 label").text()); var reducePrice = reduce*num; allReduce +=reducePrice; var count = parseFloat($(this).find(".shopping_product_list_2 label").text()); allCount +=count; }); $("#product_total").text((2)); $("#product_save").text((2)); $("#product_integral").text((2)); } </script> </head> <body> <div class="shopping_list_top">You have purchased the following products</div> <div class="shopping_list_border"> <table width="100%" border="1px solid #ccc" > <tr class="shopping_list_title" > <td class="shopping_list_title_1">Product Name</td> <td class="shopping_list_title_2">Single product points</td> <td class="shopping_list_title_3">Market price</td> <td class="shopping_list_title_4">Dangdang Price</td> <td class="shopping_list_title_5">quantity</td> <td class="shopping_list_title_6">delete</td> </tr> </table> <table width="100%" border="1px solid #ccc" > <tr class="shopping_product_list" > <td class="shopping_product_list_1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">Private equity (the first financial that discloses the secrets of capital game...</a></td> <td class="shopping_product_list_2"><label>189</label></td> <td class="shopping_product_list_3">¥<label>32.00</label></td> <td class="shopping_product_list_4">¥<label>18.90 </label>(59fold)</td> <td class="shopping_product_list_5"><input type="text" value="1"/></td> <td class="shopping_product_list_6"><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">delete</a></td> </tr> <tr class="shopping_product_list" > <td class="shopping_product_list_1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue"> Xiao Renyuan (Zhang Ailing's most mysterious novel manuscript)</a></td> <td class="shopping_product_list_2"><label>173</label></td> <td class="shopping_product_list_3">¥<label>28.00</label></td> <td class="shopping_product_list_4">¥<label>17.30</label>(62fold)</td> <td class="shopping_product_list_5"><input type="text" value="1"/></td> <td class="shopping_product_list_6"><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">delete</a></td> </tr> <tr class="shopping_product_list" > <td class="shopping_product_list_1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">The world without complaining (the world of 80 best-selling countries around the world...</a></td> <td class="shopping_product_list_2"><label>154</label></td> <td class="shopping_product_list_3">¥<label>24.80</label></td> <td class="shopping_product_list_4">¥<label>15.40</label> (62fold)</td> <td class="shopping_product_list_5"><input type="text" value="2"/></td> <td class="shopping_product_list_6"><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">delete</a></td> </tr> <tr class="shopping_product_list" > <td class="shopping_product_list_1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">Fomat Double Bucket Washing Machine XPB20-07S</a></td> <td class="shopping_product_list_2"><label>358</label></td> <td class="shopping_product_list_3">¥<label>458.00</label></td> <td class="shopping_product_list_4">¥<label>358.00</label> (78fold)</td> <td class="shopping_product_list_5"><input type="text" value="1"/></td> <td class="shopping_product_list_6"><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">delete</a></td> </tr> <tr class="shopping_product_list" > <td class="shopping_product_list_1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">PHP and MySQL Web Development (Original Book, 4th Edition)</a></td> <td class="shopping_product_list_2"><label>712</label></td> <td class="shopping_product_list_3">¥<label>95.00</label></td> <td class="shopping_product_list_4">¥<label>71.20</label> (75fold)</td> <td class="shopping_product_list_5"><input type="text" value="1"/></td> <td class="shopping_product_list_6"><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">delete</a></td> </tr> <tr class="shopping_product_list" > <td class="shopping_product_list_1"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">Fabour Insect Note</a> (Buy ¥68.30 and you can participate in the "10 yuan cash discount for every 199 yuan" event)</td> <td class="shopping_product_list_2"><label>10</label></td> <td class="shopping_product_list_3">¥<label>198.00</label></td> <td class="shopping_product_list_4">¥<label>130.70</label> (66fold)</td> <td class="shopping_product_list_5"><input type="text" value="1"/></td> <td class="shopping_product_list_6"><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="blue">delete</a></td> </tr> </table> <div class="shopping_list_end"> <div><a href="javascript:void(0);" rel="external nofollow" >Clear the shopping cart</a></div> <ul> <li class="shopping_list_end_1"><input name="" type="image" src="images/shopping_balance.gif"/></li> <li class="shopping_list_end_2">¥<label ></label></li> <li class="shopping_list_end_3">Total product amount:</li> <li class="shopping_list_end_4">You save a total of money:¥<label class="shopping_list_end_yellow" ></label><br/> Get product points:<label class="shopping_list_end_yellow" ></label> </li> </ul> </div> </div> </body> </html>
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.