laravel框架即点击改,批量删除,更新日志

<script src="jquery-1.7.2.min.js"></script>  
<center>  
<h2>商品列表</h2>  
<button id="insert">插入数据</button>  
<a href="rizhi">查看日志</a>  
{{Session::get('user')}}  
    <table border=1 >  
    <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">  
    <tr>  
        <th><input type="checkbox" name="" id=""></th>  
        <th>名称</th>  
        <th>价格</th>  
        <th>操作</th>  
     </tr>  
        @foreach($models as $v)  
        <tr>  
            <td><input type="checkbox" name="box" value="{{$v->id}}"></td>  
            <td  pid="{{$v->id}}"><span class="update">{{$v->goods_name}}</span></td>  
            <td pid="{{$v->id}}"><span class="price">{{$v->goods_price}}</span></td>  
            <td><a href="del?id={{$v->id}}">删除</a></td>  
        </tr>  
        @endforeach  
    </table>  
    <button class="pl">批量删除</button>  
    </center>  
<script>  
 $(function(){  
    $("#insert").click(function(){  
        location.href="insert";  
    })  
    //批量删除  
    $(".pl").click(function(){  
       var  box = $("input[name='box']");  
          length =box.length;  
       //alert(length);  
       var str ="";  
      for(var i=0;i<length;i++){  
           if(box[i].checked==true){  
                str =str+","+box[i].value;  
           }  

       }  
       str= str.substr(1)  
       //alert(str)    

       location.href="del?id="+str;  
    })  
    //即点击该  
    $(document).on("click", ".update", function () {    
            var con = $(this).html();    
            var pid = $(this).parent().attr('pid');    
            //alert(pid)  
            $(this).parent().html('<input type="text" value="'+con +'" class="input" pid="'+pid+'" />');    
            $("input").focus();    
            $(document).on("blur", ".input", function () {  
                var goods_name = $(this).val();    
                pid = $(this).attr("pid");  
                //alert(pid)  
                $(this).parent().html('<span class="update">'+goods_name +'</span>');   
                $.post("update",{goods_name:goods_name,pid:pid},function(msg){  
                //alert(msg)  
                location.href="login_do";  

            })   
            });    

        });  

        //即点击该  价格  
    $(document).on("click", ".price", function () {    
            var con = $(this).html();    
            var pid = $(this).parent().attr('pid');    
            //alert(pid)  
            $(this).parent().html('<input type="text" value="'+con +'" class="input" pid="'+pid+'" />');    
            $("input").focus();    
            $(document).on("blur", ".input", function () {  
                var goods_name = $(this).val();    
                pid = $(this).attr("pid");  
                //alert(pid)  
                $(this).parent().html('<span class="update">'+goods_name +'</span>');   
                $.post("price",{goods_name:goods_name,pid:pid},function(msg){  
                //alert(msg)  
                location.href="login_do";  

            })   
            });    

        });      
 })  

</script>  

后台处理

//删除  
   public function  del(){  
     $id = Request::input('id');  
     $str = explode(",",$id);  
     //var_dump($str);die;  
     foreach($str as $v){  
      DB::table('goods')->where('id',"=","$v")->delete();  
     }  

     $arr['content']="删除Id为".$id."数据";  
     $arr['date']=date("Y-m-d H:i:s");  
     $arr['u_id'] = Session::get('user');  
    DB::table('rizhi')->insert($arr);  
     return  redirect("login_do");  
   }  
    //即点击该  
   public function  update(){  
     $pid = Request::input('pid');  
    // echo $pid;die;  
     $old =  DB::table('goods')->where('id',"=","$pid")->first();  
     $old_name =  $old->goods_name;  
     $goods_name = Request::input('goods_name');  
     $res= DB::table('goods')  
           ->where('id','=',$pid)  
           ->update(array('goods_name' => $goods_name));  
     $arr['content']="Id为".$pid."数据将商品名".$old_name."修改为".$goods_name;  
     $arr['date']=date("Y-m-d H:i:s");  
     $arr['u_id'] = Session::get('user');  
     DB::table('rizhi')->insert($arr);  
        echo   1;  
     //return  redirect("login_do");  
   }  

    //即点击该  价格  
   public function  price(){  
     $pid = Request::input('pid');  
    // echo $pid;die;  
     $old =  DB::table('goods')->where('id',"=","$pid")->first();  
     $old_name =  $old->goods_name;  
     $goods_name = Request::input('goods_name');  
     $res= DB::table('goods')  
           ->where('id','=',$pid)  
           ->update(array('goods_price' => $goods_name));  
     $arr['content']="Id为".$pid."数据将价格".$old_name."修改为".$goods_name;  
     $arr['date']=date("Y-m-d H:i:s");  
     $arr['u_id'] = Session::get('user');  
     DB::table('rizhi')->insert($arr);  
        echo   1;  
     //return  redirect("login_do");  
   }  

转载自一个美女博客 http://blog.csdn.net/lwc863481702/article/details/52639839

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值