jquery implementation of Shopping cart items quantity Add and subtract function code _jquery

Source: Internet
Author: User

This article illustrates the amount of shopping cart items that jquery implements to add and subtract functions. Share to everyone for your reference, specific as follows:

Today netizens in the use of jquery to achieve the number of shopping cart items to add and subtract effects of the time encountered problems to ask me, I later helped her solve this jquery special effects, now it is sorted out to share for everyone to use, although the function is relatively simple, but very practical.

Mainly includes the following functions:

1, the quantity increases the operation function

2, the quantity reduces the operation function

3, the total price calculation function

4, automatically judge the number of times to 1, reduce the operation button to prevent clicks, increase the number of automatic recovery

5, keep the decimal point number tofixed () function is very practical

The functional code is as follows:

$ (function () {
//Get text Box object
var t = $ ("#text_box");
Quantity increase Operation
$ ("#add"). Click (function () {
t.val (parseint (T.val ()) +1)
if (parseint (T.val ())!=1) {
$ (' # Min '). attr (' disabled ', false);
}
Settotal ();
})
Quantity reduction operation
$ ("#min"). Click (function () {
t.val (parseint (T.val ())-1);
if (parseint (T.val ()) ==1) {
$ (' #min '). attr (' disabled ', true);
}
Settotal ();
})
Compute operation
Function settotal () {
$ ("#total"). HTML ((parseint (T.val ()) *3.95). ToFixed (2));//tofixed () is the function that preserves the decimal point is very practical oh/
/Initialization
settotal ();
})

More interested readers of jquery-related content can view the site's topics: A summary of jquery extension techniques, a summary of common plug-ins and usage in jquery, a summary of operational tips for jquery (table), a summary of Ajax usage in jquery, jquery Common Classic Effects Summary "jquery animation and special effects usage Summary" and "jquery Selector usage Summary"

I hope this article will help you with the jquery program design.

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.