zoukankan      html  css  js  c++  java
  • 购物车相关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';
        }
  • 相关阅读:
    关于解决win10安装mongodb启动服务失败的解决办法
    python3 Debug报错 Traceback (most recent call last)
    centos7 iptable开放端口失败的总结
    操作系统
    大数据医疗
    软件相关
    射频消融仪产品相关
    YY/T 0664—2020《医疗器械软件 软件生存周期过程》 相关
    ISO19001相关
    GMP现场指导相关
  • 原文地址:https://www.cnblogs.com/xujing6/p/6525121.html
Copyright © 2011-2022 走看看