Code for adding or subtracting the number of Shopping Cart items and jQuery item quantity implemented by jquery

Source: Internet
Author: User

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 ();})

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.