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.