您的位置:首页 > Web前端 > JQuery

jquery实现购物车非复选框总金额的变化

2017-03-14 22:23 155 查看
<script>

//支付方式
$(".object").on("click",".object-item-img",function(){

    $(this).toggleClass("select");

    GetCount();
});

//价格结算
function GetCount() {
var conts = 0;
var aa = 0;
$(".object-item .object-item-img").each(function () {
if ($(this).hasClass('select')) {
for (var i = 0; i < $(this).length; i++) {
conts += parseInt($(this).siblings('.object-information').find('p').children('i').text());
aa += 1;
}
}
});
$(".group-title").children(".fr").children("span").html((conts).toFixed(2)); 
}

 

    $(function () {
var t = $(".numOne");
var num = t.parent('.add-num').siblings('p').children('i').html();

//加号
t.prev('.add').click(function () {
t.val(parseInt(t.val()) + 1)
setTotal(); GetCount();
})

//减号
t.next('.min').click(function () {
t.val(parseInt(t.val()) - 1);
if(t.val() <= 0) {
t.val(0);
}
setTotal(); GetCount();
})
function setTotal() {
t.parent('.add-num').siblings('p').children('i').html((parseInt(t.val()) * parseInt(num)).toFixed(2));
}
setTotal();
});

   
$(function () {
var t = $(".numTwo");
var num = t.parent('.add-num').siblings('p').children('i').html();
t.prev('.add').click(function () {
t.val(parseInt(t.val()) + 1)
setTotal(); GetCount();
})
t.next('.min').click(function () {
t.val(parseInt(t.val()) - 1);
if(t.val() <= 0) {
t.val(0);
}
setTotal(); GetCount();
})
function setTotal() {
t.parent('.add-num').siblings('p').children('i').html((parseInt(t.val()) * parseInt(num)).toFixed(2));
}
setTotal();
})

$(function () {
var t = $(".numThree");
var num = t.parent('.add-num').siblings('p').children('i').html();
t.prev('.add').click(function () {
t.val(parseInt(t.val()) + 1)
setTotal(); GetCount();
})
t.next('.min').click(function () {
t.val(parseInt(t.val()) - 1);
if(t.val() <= 0) {
t.val(0);
}
setTotal(); GetCount();
})
function setTotal() {

// var price = parseInt(t.val()) * parseInt(num);

// t.parent('.add-num').parent(".object-information").siblings(".object-item-img").html(price);
t.parent('.add-num').siblings('p').children('i').html((parseInt(t.val()) * parseInt(num)).toFixed(2));
}
setTotal();
})

</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  div img input p