$('.del').click(function() {
var nid = $(this).attr('data-id')*1;
delNews(nid);
});
$('.multi-del').click(function() {
var checkedItems = $('.list-tbl tbody').first().find(':checkbox:checked'),
nids = new Array();
if (checkedItems.size() <= 0) {
$.kw.alert('没有选择操作对象!');
return false;
} else {
$.each(checkedItems, function (i, o) {
nids.push($(o).val()*1);
});
delNews(nids.join(','));
}
});
function delNews(nids) {
$.kw.confirm('确定要删除吗?', function() {
$.ajax({
type:'POST',
url:'__URL__/delHistoric',
data:{'nids' : nids},
async:false,
dataType:'json',
beforeSend:function() {
},
success:function(re) {
if (re.stat*1) {
$.kw.alert('操作成功!', '', function() {
window.location.reload();
});
} else {
$.kw.alert(re.msg);
}
},
error:function() {
$.kw.alert('操作失败!请刷新页面后重试……');
}
});
});
}
//控制器
public function DelHelp(){
$ids = trim(I('post.nids'));
if (empty($ids)) {
die(json_encode(array('stat'=>0, '请求参数错误!')));
}
$idsArr = explode(',', trim($ids, ','));
if (count($idsArr) <= 0) {
die(json_encode(array('stat'=>0, '请求参数错误!')));
}
$model = M('Help');
$result = $model->where(array('id'=>array('in', $idsArr)))->delete();
if ($result !== false) {
die(json_encode(array('stat'=>1, '操作成功!')));
} else {
die(json_encode(array('stat'=>0, '操作失败![原因]:' . $model->getError())));
}
}
///////////////////////以下为模板部分//////////////////////////////////////
<div class="data-list">
<table class="table table-hover list-tbl">
<thead>
<tr>
<!--<th width="60">#ID</th>-->
<th width="36"><input type="checkbox" class="select-all" title="全选/全不选"></th>
<th width="90">照片</th>
<th width="80">教师姓名</th>
<th width="40">性别</th>
<th width="160">部门</th>
<th width="160">科目</th>
<th >班级</th>
<th width="200">操作</th>
</tr>
</thead>
<tbody>
<form name="listform" id="listform" action="" method="get">
<input type="hidden" name="dotype" id="dotype" value="list">
<input type="hidden" name="ids" id="ids" value="">
<volist name="datas" id="vo">
<tr>
<!--<td width='60'>{$vo.id}</td>-->
<td><input type="checkbox" name="pid" id="pid" value="{$vo.id}"></td>
<td width='60'><a href="/{$Think.config.UPLOAD_COMM_PATH}{$vo.imagePath}" class="tip" title="{$vo.name}" target="_blank"><img src="/{$Think.config.UPLOAD_COMM_PATH}{$vo.imagePath}" style="width:30px;height:30px;"></a></td>
<td>{$vo.name}</td>
<td>{$vo.sex}</td>
<td>{$vo.departmentName}</td>
<td>{$vo.subjectName}<?php //var_dump($vo['subjectId']);?></td>
<td>{$vo.banjiName}</td>
<td>
<a class="oper edit" href="__URL__/editTeacher/id/{$vo.id}" title="编辑"><i class="icon-pencil"></i></a>
<a class="oper del" href="javascript:void(0);" data-url="__URL__/delTeacher/id/{$vo.id}" title="删除"><i class="icon-trash"></i></a>
</td>
</tr>
</volist>
</tbody>
</table>
<table class="table">
<tr>
<td>
<input type="checkbox" class="select-all" title="全选/全不选">
<button type="button" class="btn btn-default btn-sm multi-del" style="margin-left:30px;">批量删除</button>
</td>
<td class="page-box text-right" width="80%">{$page}</td>
</tr>
</table>
</form>
</div>
///////////////////模板部分结束///////////////////////////////////
//////////////////以下为全选的脚本实现代码////////////////
$(function($) {
|
|
|
| $('form').delegate(':input', 'keypress', function(e) {
|
| if (e.keyCode == 13) {
|
| e.preventDefault();
|
| }
|
| });
|
|
|
|
|
| $('input').iCheck({
|
| checkboxClass: 'icheckbox_flat-green',
|
| radioClass: 'iradio_flat-green',
|
| increaseArea: '20%' // optional
|
| });
|
|
|
|
|
| /* ------------------------ table - dataList 全选 / 全不选 ------------------------ */
|
| var tblObj = $('.list-tbl').first().find('tbody');
|
| $('.select-all').click(function(){
|
| var isChecked = $(this).prop('checked');
|
| $('.select-all').prop({'checked' : isChecked});
|
| tblObj.find(':checkbox').prop({'checked' : isChecked});
|
| });
|
|
|
| tblObj.first().find(':checkbox').click(function(){
|
| var allItems = tblObj.find(':checkbox').size(),
|
| checkedItems = tblObj.find(':checkbox:checked').size();
|
| $('.select-all').prop({'checked' : (allItems == checkedItems)});
|
| });
|
|
|
| /*
|
| * 以上是对默认样式的input操作处理,
|
| * --------------------------------
|
| * 以下是对icheck样式的input操作处理
|
| */
|
|
|
| $('.select-all').siblings('ins').click(function(){
|
| var isChecked = $(this).siblings('.select-all').first().prop('checked');
|
| $('.select-all').prop({'checked' : isChecked});
|
| tblObj.find(':checkbox').prop({'checked' : isChecked});
|
|
|
| if (isChecked) {
|
| $('.select-all').parent('div').addClass('checked');
|
| tblObj.find(':checkbox').parent('div').addClass('checked');
|
| } else {
|
| $('.select-all').parent('div').removeClass('checked');
|
| tblObj.find(':checkbox').parent('div').removeClass('checked');
|
| }
|
| });
|
|
|
| tblObj.first().find(':checkbox').siblings('ins').click(function(){
|
| var allItems = tblObj.find(':checkbox').size(),
|
| checkedItems = tblObj.find(':checkbox:checked').size();
|
| $('.select-all').prop({'checked' : (allItems == checkedItems)});
|
|
|
| if (allItems == checkedItems) {
|
| $('.select-all').parent('div').addClass('checked');
|
| } else {
|
| $('.select-all').parent('div').removeClass('checked');
|
| }
|
| });
|
| /* ------------------------ table - dataList 全选 / 全不选 结束 ------------------------ */
|
|
|
| });
|
| </script>
|
评论