tp5 全选,全不选 ,ajax批量删除
作者:互联网
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>显示</title> </head> <body> <table border="1"> <tr> <th></th> <th>ID</th> <th>姓名</th> <th>性别</th> <th>年龄</th> <th>操作</th> </tr> {volist name="info" id='v'} <tr> <td><input type="checkbox" name="aaa" value="{$v.id}"></td> <td>{$v.id}</td> <td>{$v.name}</td> <td> <?php if($v['sex']==1){ echo "男"; } if($v['sex']==2){ echo "女"; } ?> </td> <td>{$v.age}</td> <td> <a href="/index.php/index/Test/update?id={$v.id}">修改</a> <a href="/index.php/index/Test/delete?id={$v.id}">删除</a> </td> </tr> {/volist} </table> <input type="button" value="全选" id="checkall"> <input type="button" value="反选" id="checkalls"> <input type="button" value="删除" id="ddd"> <br> <a href="/index.php/index/Test/add">返回添加</a> </body> </html>
jq代码:
<script type="text/javascript" src="/jquery-3.4.1.js"></script> <script type="text/javascript"> //全选 $('#checkall').click(function(){ $("input[type='checkbox']").attr("checked",true); }) //反选 $('#checkalls').click(function(){ $("input[type='checkbox']").attr("checked",false); }) //删除 $('#ddd').click(function(){ var chk_value =[];//定义一个数组 $('input[name="aaa"]:checked').each(function(){ chk_value.push($(this).val()); }); // alert(chk_value); $.ajax({ type:"POST", url:"delall", data:{ id:chk_value }, success:function(e){ if(e==1){ alert('删除成功'); location.href="list"; } } }) }) </script>
控制器代码
//批量删除 public function delall(){ // echo "批量删除"; $ids=input('post.'); $id=$ids['id']; $data=Db::table('test')->delete($id); if($data){
//这里可以返回json数据格式 return 1; }else{ return 2; }
标签:function,删除,chk,ajax,value,tp5,全选,input,id 来源: https://www.cnblogs.com/xiaoyantongxue/p/15221615.html