html
<button class="batchdel" id="submitbatchdel" type="submit">
<a href="" onclick="if(confirm('确定要删除数据吗?')) return true;else return false;">批量删除</a>
</button>
jQuery
$("#submitbatchdel").bind('click', function () {
var selectItem = new Array();
$("input[name='batchdel']:checked").each(function() {
selectItem.push($(this).val());//在数组中追加元素
});
$('.active').html('');
if (selectItem == '') {
errorDis('请选择图片');
return false;
}
$.ajax({
url: "del/batchdel",
type: 'POST',
dataType: 'json',
data: 'items=' + selectItem.join(","),
success: function (data) {
if (data.code == 200) {
errorDis(data.info);
refresh();
} else {
errorDis(data.info);
return false;
}
}
});
});
php
public function batchdelAction() {
//接收到的图片id字符串
$items=$_POST['items'];
$photoModel = new Model_Photo();
$where = "id in(".$items.")";
$res = $photoModel->deletePhoto($where);
if($res){
exit(json_encode(array('code'=>200, 'info'=>"图片删除成功")));
}else{
exit(json_encode(array('code'=>-1, 'info'=>"删除失败")));
}
}