您的位置:首页 > 编程语言 > PHP开发

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

2016-11-29 17:33 441 查看
html

<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)  <
d32a
/li>       //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> 

php

//删除  
   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");  
   } 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php html 框架