亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

統(tǒng)計購物車所有勾選商品的總價

Original 2019-05-03 19:29:16 450
abstract:$(function(){     //初始化總價, 總選擇數(shù), 總條數(shù);     doPrice();     //全選/選擇框的鼠標移上變個顏色     $('.fa-check').mouseove
$(function(){
    //初始化總價, 總選擇數(shù), 總條數(shù);
    doPrice();
    //全選/選擇框的鼠標移上變個顏色
    $('.fa-check').mouseover(function(){
        if($(this).attr('class')!='fa fa-check checked') {
            $(this).css('color', '#ff6a00');
        }
    })
    $('.fa-check').mouseleave(function(){
        $(this).css('color','#fff');
    })

    //普通勾選
    $('.fa-check').click(function(){
        var cla=$(this).attr('class');
        if(cla!='fa fa-check checked'){
            $(this).attr('class','fa fa-check checked');
        }else{
            $(this).attr('class','fa fa-check');
        }
        doCheckAll();
        doPrice();
    })

    //全選框勾選
    $('#check-all').click(function () {
        var cla=$(this).attr('class');
        if(cla!='fa fa-check checked'){
            $('.fa-check').attr('class','fa fa-check checked');
        }else{
            $('.fa-check').attr('class','fa fa-check');
        }
        doPrice();
    })

    //檢查是否全選
    function doCheckAll(){
        var allitem=$('.list-item i[class*="fa-check"]').length;
        var checkeditem=$('.list-item i[class$="checked"]').length;
        if(allitem!=checkeditem){
            $('#check-all').attr('class','fa fa-check');
        }else{
            $('#check-all').attr('class','fa fa-check checked');
        }
    }



    //加減按鈕

    $('button.minus').click(function(){
        var nowvalue=$(this).siblings('input').val();
        nowvalue=parseInt(nowvalue);
        var currentvalue=0;
        nowvalue<=1?currentvalue=1:currentvalue=nowvalue-1;
        $(this).siblings('input').val(currentvalue);

        //計算當前的小計
        var danjia=parseFloat($(this).parents('.good-num').siblings('.good-price').html());
        var xiaoji=danjia*currentvalue;
        $(this).parents('.good-num').siblings('.good-total-price').html(xiaoji+'元');

        //更新總價
        doPrice();
    })

    $('button.plus').click(function(){
        var nowvalue=$(this).siblings('input').val();
        nowvalue=parseInt(nowvalue);
        var currentvalue=nowvalue+1;
        $(this).siblings('input').val(currentvalue);

        //計算當前的小計
        var danjia=parseFloat($(this).parents('.good-num').siblings('.good-price').html());
        var xiaoji=danjia*currentvalue;
        $(this).parents('.good-num').siblings('.good-total-price').html(xiaoji+'元');

        //更新總價
        doPrice();
    })

    function doPrice(){
        //統(tǒng)計所有勾選了的值;
        var items=$('.list-item i[class*="fa-check"]');
        var checkeditems=$('.list-item i[class$="checked"]').parents('.select').siblings('.good-total-price')
        var totalprice=0;
        for(var i=0;i<checkeditems.length;i++){
            totalprice+=parseFloat(checkeditems[i].innerHTML);
        }
        //改總價
        $('.sum-price').html(totalprice);
        //改選中數(shù)
        $('.select-count').html(checkeditems.length);
        //改總條數(shù)
        $('.all-count').html(items.length);

    }
})

QQ圖片20190503192839.png

Correcting teacher:查無此人Correction time:2019-05-05 10:35:28
Teacher's summary:完成的不錯。購物車不能分頁,所以購物車數(shù)量要限制。里面商品不能太多。繼續(xù)加油。

Release Notes

Popular Entries