批量刪除
<td width="50%" style="text-align: left;">
<button class="btn-common-delete" onclick="batchDelete()" >批量刪除</button>
</td>
<script type="text/javascript">
function LoadingInfo(page_index) {
var search_text = $("#search_text").val();
$.ajax({
type : "post",
url : "{:__URL('ADMIN_MAIN/shaidan/wentifangkui')}",
data : { "page_index" : page_index, "page_size" : $("#showNumber").val(), "search_text" : search_text },
success : function(res) {
var obj =$.parseJSON(res);
var html = '';
if (res.length > 0) {
$(".table-class tbody").empty();
$.each(eval(res), function(i, j){
console.log(j);
html += '<tr align="center">';
html += '<td><i class="checkbox-common"><input name="sub" type="checkbox" value="'+j.id+'"></i></td>';
html += '<td align="left" title="'+j.nick_name+'">' + j.nick_name+ '</td>';
html += '<td>'+j.content+'</td>';
html += '<td>'+j.phone+'</td>';
html += '<td>' +j.addtime+'</td>';
html += '<td>';
html += '<a style="cursor: pointer;" οnclick="deleteArticle('+j.id+')">刪除</a></td>';
})
$(".table-class tbody").html(html);
} else {
var html = '<tr align="center"><td colspan="8">暫無文章</td></tr>';
$(".table-class tbody").html(html);
}
initPageData(res['page_count'],res.length,obj.length);
$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
}
});
}
function batchDelete() {
var article_id= new Array();
$(".table-class tbody input[type='checkbox']:checked").each(function() {
if (!isNaN($(this).val())) {
article_id.push($(this).val());
}
});
if(article_id.length ==0){
$( "#dialog" ).dialog({
buttons: {
"確定,#0059d6,#fff": function() {
$(this).dialog('close');
}
},
contentText:"請選擇需要操作的記錄",
title:"訊息提醒",
});
return false;
}
deleteArticle(article_id);
}
var flag = false;
function deleteArticle(article_id){
console.log(article_id);
$( "#dialog" ).dialog({
buttons: {
"確定": function() {
$(this).dialog('close');
if(!flag){
flag = true;
$.ajax({
type : "post",
url : "{:__URL('ADMIN_MAIN/shaidan/delete')}",
data : { "id" : article_id.toString() },
dataType : "json",
success : function(data) {
console.log(data);
if(data>=1){
showTip(data["message"],'success');
location.reload()
}
else{
showTip(data["message"],'error');
flag = false;
}
}
})
}
},
"取消,#f5f5f5,#666": function() {
$(this).dialog('close');
}
},
contentText:"是否刪除文章?",
});
}
function searchData(){
LoadingInfo(1);
}
</script>
public function delete()
{
if (request()->isAjax()) {
$ids=input('post.');
$id=$ids['id'];
$arr=array($id);
foreach ($arr as $key=>$value) {
$retval=Db::name('ns_member_yijianfangkui')->delete($id);
}
return json_encode($retval);
}
}