Home > php教程 > PHP开发 > Function code for adding and subtracting the number of shopping cart items implemented by jQuery

Function code for adding and subtracting the number of shopping cart items implemented by jQuery

高洛峰
Release: 2016-12-06 16:02:00
Original
2093 people have browsed it

The example in this article describes the function of adding and subtracting the number of shopping cart items implemented by jQuery. Share it with everyone for your reference, the details are as follows:

Today, netizen Cui Er encountered a problem when using Jquery to implement the special effect of adding and subtracting the number of items in the shopping cart and asked me. I later helped her solve this Jquery special effect, and now it I compiled it and shared it for everyone to use. Although the function is relatively simple, it is very practical.

Mainly includes the following functions:

1. Quantity increase operation function

2. Quantity reduction operation function

3. Total price calculation function

4. When the quantity is automatically judged to 1, the decrease operation button is prohibited from clicking. Automatically restore when the quantity increases

5. The toFixed() function to retain the number of decimal points is very practical

The function code is as follows:

$(function(){
//获得文本框对象
var t = $("#text_box");
//数量增加操作
$("#add").click(function(){
t.val(parseInt(t.val())+1)
if (parseInt(t.val())!=1){
$('#min').attr('disabled',false);
}
setTotal();
})
//数量减少操作
$("#min").click(function(){
t.val(parseInt(t.val())-1);
if (parseInt(t.val())==1){
$('#min').attr('disabled',true);
}
setTotal();
})
//计算操作
function setTotal(){
$("#total").html((parseInt(t.val())*3.95).toFixed(2));//toFixed()是保留小数点的函数很实用哦
}
//初始化
setTotal();
})
Copy after login

​​


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template