<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');
}