购物车相关Js代码

//购物车  让总计放生变化
$('.check').click(function(){
    totals();

})

function totals(){
        var total = 0;
        $('input[type=chechbok]:checked').each(function(){

//小计加
        total += parseInt($(this).parents('tr').find('.amount').text());
        })
        $('#total').text(total
//全选
    $('.qx').click(function(){
        $('.check').each(function(){
            this.checked = true;
        })

        totals();

        //阻止默认行为
        return false;
    })

 

    //
    $('.plus').click(function(){
        var pv = $(this).prev().val();
        pv++;
        //

      $(this).prev().val(pv);

        var pri = $(this).parents('tr').find('.price').text();
        $(this).parents('tr').find('.amant').text(pri*pv);

    })
    //
    $('.minus').click(function(){
        var pv = $(this).prev().val();
        pv--;
        if( pv <= 1){
            pv = 1;
        }
        //
    

      $(this).nextAll().val(pv);

        var pri = $(this).parents('tr').find('.price').text();
        $(this).parents('tr').find('.amant').text(pri*pv);

    })

 


 

    //删除
    $('.remove').click(function(){
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        //
        var id = $(this).parent().parent().parent('div').find('.check').attr('gid');
        var trs = $(this).parent().parent().parent('div');

        $.post('/home/shop',{id:id},function(data){
        // alert(id);
        console.log(data);

            if(data == 1){
                // console.log('123');
                trs.remove();
                // totals();
            }
        })
    })

控制器相关代码

    public function store(Request $request )
    {
        //
        $id = $request->input('id');
        $res = Session::get('cartt');
// var_dump($res);

        foreach($res as $k => $v){

            if($v['id']==$id){

                Session::forget('cartt');
                return '1';
            }
        }
        return '0';
    }

 

posted @ 2017-03-09 12:50  虚镜  阅读(284)  评论(0编辑  收藏  举报