1 public function ajaxxiu(request $request)
2 {
3 $id = $request->post('id');
4 $fd = $request->post('fd');
5 $new_val = $request->post('new_val');
6 $res = DB::table('users')->where('id',$id)->update([$fd=>$new_val]);
7 if ($res){
8 return 1;
9 }
10 }
1 <!doctype html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <meta name="viewport"
6 content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7 <meta http-equiv="X-UA-Compatible" content="ie=edge">
8 <title>展示頁面</title>
9 <link rel="stylesheet" href="{{asset('css/bootstrap.css')}}">
10 </head>
11 <body>
12 <center><h1>數據展示頁面</h1></center>
13 <input type="text" name="search" id="search"><input type="button" class="page" value="搜索">
14 <table class="table table-striped">
15 {{--@csrf--}}
16 <tr>
17 <td><input type="checkbox" id="check"></td>
18 <td>編號</td>
19 <td>用戶名</td>
20 <td>性別</td>
21 <td>郵箱</td>
22 <td>創建時間</td>
23 <td>修改時間</td>
24 <td>操作</td>
25 </tr>
26 <tbody id="tb">
27 @foreach($data as $key=>$val)
28 <tr id="{{$val->id}}">
29 <td><input type="checkbox" name="check" value="{{$val->id}}"></td>
30 <td>{{$val->id}}</td>
31 <td fd="username">{{$val->username}}</td>
32 @if($val->sex == 0 )
33 <td id="{{$val->id}}" class="se" fd="{{$val->sex}}">男</td>
34 @elseif($val->sex == 1)
35 <td id="{{$val->id}}" class="se" fd="{{$val->sex}}">女</td>
36 @endif
37 <td fd="email">{{$val->email}}</td>
38 <td>{{$val->created_at}}</td>
39 <td>{{$val->updated_at}}</td>
40 <td><a href="javascript:void (0)" id="{{$val->id}}" class="del">刪除</a>|<a href="update?id={{$val->id }}">編輯</a></td>
41 </tr>
42 @endforeach
43 </tbody>
44 </table>
45 <input type="hidden" name="a_page" id="a_page" value="1">
46 <input type="hidden" name="last_page" id="last_page" value="{{$end}}">
47 <a href="javascript:void (0)" class="page">首頁</a>
48 <a href="javascript:void (0)" class="page">上一頁</a>
49 <a href="javascript:void (0)" class="page">下一頁</a>
50 <a href="javascript:void (0)" class="page">尾頁</a>
51 <button class="del_all">批刪</button>
52 </body>
53 </html>
54 <script src="../js/jquery-3.3.1.min.js"></script>
55 //及時更改
56 $(document).on("dblclick","td",function () {
57 var id = $(this).parent().attr('id');
58 var fd = $(this).attr('fd');
59 if (fd==undefined){
60 alert("不能修改");
61 return;
62 }
63 var text = $(this).text();
64 var that = $(this);
65 $(this).html('<input type="text" value="'+text+'" class="xiu">');
66 $(".xiu").blur(function () {
67 var new_val = $(this).val()
68 $.ajax({
69 url:"ajaxxiu",
70 type:"post",
71 dataType:"json",
72 data:{
73 id:id,
74 fd:fd,
75 new_val:new_val,
76 },
77 success:function (data) {
78 if (data==1){
79 that.html(new_val);
80 }
81 }
82 })
83 })
84 })