jquery全選択と全選択解除、単一削除と一括削除
すべて
キャンセル
//
function Select(){
var sel=document.getElementsByName("a[]");
for(var i=0;i<sel.length;i++){
sel[i].checked=true;
}
}
//
function Cancel(){
var sel=document.getElementsByName("a[]");
for(var i=0;i<sel.length;i++){
sel[i].checked=false;
}
}
//
function delete_item(id) {
var a = confirm(' ?');
if(a){
$.post("{:U('Admin/Company/classDelete')}" ,{"id":id}, function(data, textStatus) {
if (data == 'success') {
alert(' , !');
location.reload();
} else {
alert(' , !');
}
});
}
}
//
function batch_delete()
{
var a = confirm(' ?');
if(a){
var question_class_ids = '';
var count = 0;
$('input[name="a[]"]:checked').each(function(){
count ++;
question_class_ids += $(this).val() + ',';
});
if (!count) {
alert(' , !');
return;
}
question_class_ids = question_class_ids.substr(0, question_class_ids.length - 1);
$.post('{:U("Admin/Company/classDelete")}', {"id":question_class_ids}, function(data, textStatus){
if (data == 'success') {
alert(' , !');
location.reload();
} else {
alert(' , !');
}
});
}
}
php:
public function classDelete(){
if(IS_POST && IS_AJAX){
$id = I('post.id');
$id_array = explode(',',$id);
$obj = M('space');
foreach($id_array AS $k => $v) {
$obj->where('id=%d', intval($v))->delete();
}
exit('success');
}
exit('failure');
}