Code for adding or subtracting the number of Shopping Cart items and jQuery item quantity implemented by jquery
This example describes how to add or subtract the number of cart items in jQuery. We will share this with you for your reference. The details are as follows:
Today, the netizen Cui er asked me a question when using Jquery to add or subtract the number of items in the shopping cart. I then helped her solve this Jquery special effect, now I want to sort it out and share it with everyone. Although the function is simple, it is very practical.
It mainly includes the following features:
1. added operation functions in quantity
2. quantity reduction operation function
3. Total price calculation
4. When the number is automatically determined to be 1, the reduce operation button is not allowed to be clicked. When the number is increased, the operation is automatically restored.
5. The toFixed () function is very practical.
The function code is as follows:
$ (Function () {// get the text box object var t = $ ("# text_box"); // increase the number of operations $ ("# add "). click (function () {t. val (parseInt (t. val () + 1) if (parseInt (t. val ())! = 1) {$ ('# min '). attr ('Disabled ', false) ;}settotal () ;}) // reduce the number of operations $ ("# min "). click (function () {t. val (parseInt (t. val ()-1); if (parseInt (t. val () = 1) {$ ('# min '). attr ('Disabled ', true) ;}settotal () ;}) // calculate the operation function setTotal () {$ ("# total" ).html (parseInt (t. val () * 3.95 ). toFixed (2); // toFixed () is a very useful function for retaining the decimal point.} // initialize setTotal ();})