Home >Web Front-end >JS Tutorial >jQuery implements addition and subtraction of the quantity of multiple items in the shopping cart and total price calculation_jquery

jQuery implements addition and subtraction of the quantity of multiple items in the shopping cart and total price calculation_jquery

WBOY
WBOYOriginal
2016-05-16 16:45:481382browse
Copy code The code is as follows:




jQuery implements the calculation of the total price of multiple items in the shopping cart

<script> <br>$(function(){ <br> $(".add").click(function(){ <br>var t=$(this).parent().find('input[class*=text_box]'); <br>t.val(parseInt (t.val()) 1) <br>setTotal(); <br>}) <br>$(".min").click(function(){ <br>var t=$(this).parent ().find('input[class*=text_box]'); <br>t.val(parseInt(t.val())-1) <br>if(parseInt(t.val())<0 ){ <br>t.val(0); <br>} <br>setTotal(); <br>}) <br>function setTotal(){ <br>var s=0; <br>$(" #tab td").each(function(){ <br>s =parseInt($(this).find('input[class*=text_box]').val())*parseFloat($(this).find ('span[class*=price]').text()); <br>}); <br>$("#total").html(s.toFixed(2)); <br>} <br>setTotal(); <br><br>}) <br></script>










Unit price:1.50




Unit price:3.95





< ;p>Total price:




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn