<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>Document</title> <script type="text/javascript" src="/js/jquery-3.0.0.js"></script> </head> <body> <center> <table border="1"> <tr> <th>编号</th> <th>姓名</th> <th>密码</th> </tr> <?php foreach($content as $v):?> <tr> <td><input type="checkbox" class="checks" value="<?php echo $v->id?>"><?php echo $v->id ?></td> <td class="click" upt_id="<?php echo $v->id?>"><?php echo $v->name ?></td> <td><?php echo $v->password ?></td> </tr> <?php endforeach;?> </table> <tr> <td> <button class="all">全选</button> <button class="noall">全不选</button> <button class="fanall">反选</button> <button class="alldelete">批量删除</button> <button class="tian">+</button> </td> </tr> <form action="insertadd" method="post"> <table class="alladd"></table> <input type="submit" value="提交"> </form> </center> </body> </html> <script> /** * 全选 */ $('.all').click(function(){ var ids = $('input:checkbox'); $.each(ids,function(i,item){ ids[i].checked=true; }) }) /** * 全不选 */ $('.noall').click(function(){ var ids = $('input:checkbox'); $.each(ids,function(i,item){ ids[i].checked=false; }) }) /** * 反选 */ $('.fanall').click(function(){ var ids = $('input:checkbox'); $.each(ids,function(i,item){ ids[i].checked=!ids[i].checked; }) }) /** * 批量删除 */ $(document).on('click','.alldelete',function(){ var ids = $('.checks'); var str=""; $.each(ids,function(i,item){ if(ids[i].checked==true){ str=str+','+ids[i].value; } }) var new_str=str.substr(1); $.get('alldet',{id:new_str},function(msg){ //alert(msg) /* $.each(ids,function(i,item){ if(ids[i].checked==true){ $('.checks'+ids[i].value).remove(); } })*/ if(msg==1){ location.href='orderlist'; } }) }) /** * 批量添加 */ $('.tian').click(function(){ var show=$('.alladd'); show.append("<tr><td>用户名:</td><td><input type='text' name='username[]'></td></tr><tr><td>密码:</td><td><input type='password' name='pwd[]'></td> </tr>"); }) /** * 传入值入库 */ $('.allsubmit').click(function(){ var name=""; var name=name+$('#username').val(); var pwd=$('#pwd').val(); alert(name) }) //即点即改 $(".click").click(function() { var td = $(this); var txt = td.text(); var input = $("<input type='text'value='" + txt + "'/>"); td.html(input); input.click(function () { return false; }); //获取焦点 input.trigger("focus"); //文本框失去焦点后提交内容,重新变为文本 input.blur(function () { var newtxt = $(this).val(); // alert(newtxt); //判断文本有没有修改 if (newtxt != txt) { td.html(newtxt); //在获取修改选项的id var id=td.attr('upt_id'); //alert(id) $.get('upte',{name:newtxt,id:id},function(msg){ // alert(msg) }); }else{ td.html(txt); } }) }) </script> php页面/** * 数据查询,渲染页面 */ public function orderlist(){ $arr=DB::table('fuck')->get(); // print_r($arr);die; return view('login.list',['content'=>$arr]); } /** * 接受批量删除的id */ public function alldet(Request $request){ $ids=explode(",",$request->input('id')); // print_r($ids);die; $res=DB::table('fuck')->whereIn('id',$ids)->delete(); if($res){ echo 1; }else{ echo 0; } } /** * 即点即改 */ public function upte(){ $name=$_GET['name']; $ids=$_GET['id']; //echo $name;die; $res=DB::table('fuck')->where(['id'=>$ids])->update(['name'=>$name]); if($res){ echo 1; }else{ echo 0; } } /** * 批量添加入库 */ public function insertadd(){ //设置一个静态变量 static $data=""; $name=$_POST['username']; $pwd=$_POST['pwd']; //print_r($pwd); foreach($name as $key=>$val){ $data[$key]['name']=$val; $data[$key]['password']=$pwd[$key]; } $res=DB::table('fuck')->insert($data); if($res){ return redirect('orderlist'); }else{ echo 2; } }
基本的全选,反选,全不选.批删,批量添加.即点即改
最新推荐文章于 2021-12-02 14:44:34 发布