博主信息
博文 91
粉丝 2
评论 4
访问量 146759
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
tp5 全选 反选
夏日的烈风的博客
原创
1992人浏览过

<table class="table table-bordered table-hover">
   <thead class="">
   <tr>
       <th class="text-center"  width="10%">选择</th>
       <th class="text-center" width="10%">ID</th>

       <th class="text-center">医生名称</th>

       <th class="text-center" width="20%">操作</th>
   </tr>
   </thead>
   <tbody>
   {volist name="result" id="conf"}
   <tr> <td align="center">
       <input type="checkbox" name="box" value="<?php echo $conf['id'];?>" class="checkbox" style="opacity:1;left:50px;!important; " >
   </td>

       <td align="center">{$conf.id}</td>
       <td align="center">{$conf.docname}</td>

       <td align="center">
           <a href="{:url('edit',array('id'=>$conf['id']))}" class="btn btn-primary btn-sm shiny">
               <i class="fa fa-edit"></i> 编辑
           </a>
           <a href="javascript:;" attr_id="{$conf['id']}"  attr-message="删除" class="btn btn-danger btn-sm shiny delete" onclick="dele({$conf.id})">
               <i class="fa fa-trash-o"></i> 删除
           </a>
       </td>
   </tr>
   {/volist}

   </tbody>
</table>

<div>
   <a class="btn btn-default" onclick="qx()" >全选</a>
   <a class="btn btn-default" onclick="reves()">反选</a>

   <a class="btn btn-danger choice" onclick="delchoice()">选择性删除</a>
</div>



function qx(){   //全选
   $(":checkbox").prop("checked",true );
}
function checkNo(){  //不选
   $(":checkbox").prop("checked",false);
}
function reves(){  //反选
   $.each($(":checkbox"),function(){
       $(this).prop("checked",!$(this).prop("checked"));
   });
}



function delchoice() {
   var ids = '';
   $('.checkbox').each(function () {
       if ($(this).is(':checked')) {
           ids += ',' + $(this).val(); //逐个获取id
       }
   })
   ids = ids.substring(1); // 对id进行处理,去除第一个逗号
   if (ids.length == 0) {
       layer.msg('请选择要删除的选项');
   }else{
       layer.confirm('确定要删除吗?', {
           btn: ['确定', '取消'] //按钮
       }, function () {
           $.ajax({
               type: 'get',
               url: 'del',
               data: "ids=" + ids,
               dataType: 'json',
               success: function (res) {
                   if (res.code == '1') {
                       layer.msg(res.msg, {icon: 1, time: 2000});
                       setTimeout(function () {
                           window.location.reload();
                       }, 1500)
                   } else {
                       layer.msg(res.msg, {icon: 5})
                   }
               }
           })
       }, function () {

       });
   }

}

php部分:

//全选操作
public function del(){
   $ids = explode(',',input('param.ids'));
   if (empty($ids)){
       $this->error('请传入id');
   }
   if (!Request::instance()->isAjax()) {
       $this->error('你四不四迷路?', 'BookOrder/lst');
   }

   foreach ($ids as $id) {

     $res =   $this->model->where(['id'=>$id])->update(['status'=>0]);

   }
   return  show(1,'删除成功','','BookOrder/lst');
}

本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学