This article will introduce you to a very useful jquery shopping cart real-time settlement instance program, as long as it is used by B2C e-commerce websites, you can achieve fast and no new settlement.
The function code is as follows:
| The Code is as follows: |
Copy code |
$ (Function (){ $ (". Child_tab tr: last-child"). find ("td" ).css ({borderBottom: 'none '}) // Obtain the text box object Var t = $ (". amount-input "); // Add quantity operation $ (". Amount-up"). click (function (e ){ Var c1 = parseInt ($ (this). prev (). val ()); $ (This). prev (). val (c1 + 1 ); E. preventDefault () SetTotal (); }); // Quantity reduction operation $ (". Amount-down"). click (function (e ){ Var c1 = parseInt ($ (this). next (). val ()); If (c1> = 1 ){ $ (This). next (). val (c1-1 ); }; E. preventDefault () SetTotal (); }); Function setTotal (){ // Obtain the value of each condition Var num1 = $ (". sum1"). text (); Var num2 = $ (". sum2"). text (); Var num3 = $ (". sum3"). text (); Var total = 0; Var x1 = 4, x2 = 10, x3 = 49; // Traverse the total number of parts T. each (function (index, ele ){ Total + = parseInt ($ (ele). val ()); }); $ (". Figure" detail .html (total ); // Determine which quantity meets the requirements If (total <x2 ){ B2 = num1 } Else if (total> = x2 & total <= x3 ){ B2 = num2 } Else if (total> = x3 ){ B2 = num3 } $ (". Money" into .html (total * b2). toFixed (2) + 'meta'); // toFixed () is a very useful function to retain the decimal point. } // Initialization SetTotal (); }) |
The effect is as follows:
Full instance: http://file.bKjia. c0m/upload/2013/09/taobao.rar