博客列表 >tp5 全选 反选

tp5 全选 反选

夏日的烈风的博客
夏日的烈风的博客原创
2018年12月17日 17:27:381786浏览

<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 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议