<?php
header('content-type:text/html;charset=utf-8');
$pdo
=
new
PDO('mysql:host=localhost;dbname=***;','root','root');
$pdo
->
exec
('set names utf8');
$sql
='select * from ***';
$info
=
$pdo
->query(
$sql
)->fetchAll(PDO::FETCH_ASSOC);
?>
<center>
<table border=
"1"
>
<tr>
<td>id</td>
<td>title</td>
<td>content</td>
</tr>
<?php
foreach
(
$info
as
$k
=>
$v
){ ?>
<tr>
<td><input type=
"checkbox"
name=
"box"
value=
"<?= $v['id'] ?>"
><?=
$v
['id'] ?></td>
<td><?=
$v
['title'] ?></td>
<td><?=
$v
['content'] ?></td>
</tr>
<?php } ?>
</table>
<button>批量删除</button>
</center>
<script src=
"../jquery.1.12.min.js"
></script>
<script>
$(
function
(){
$('button').click(
function
(){
var
ids=$(':checkbox');
var
str='';
var
count
=0;
for
(
var
i=0;i<ids.length;i++){
if
(ids.eq(i).is(':checked')){
str+=','+ids.eq(i).val();
count
++;
}
}
var
str=str.
substr
(1);
if
(confirm('你确定要删除这'+
count
+'条数据吗?')){
$.ajax({
type:'get',
url:'adminDel.php',
data:{str:str},
success:
function
(res){
if
(res>0){
alert('删除成功');
for
(
var
i=ids.length-1;i>=0;i--){
if
(ids.eq(i).is(':checked')){
ids.eq(i).parent().parent().remove();
}
}
}
}
})
}
return
false;
});
})
</script>