You are here
laravel框架即点击改,批量删除,更新日志
星期三, 2017-08-23 11:16 — adminshiping1
版权声明:本文为博主原创文章,未经博主允许不得转载。- <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