php的批量删除有3个部分:1.是全选的js代码;2.是php删除代码我不是用类写的,大家一看就能看懂;3.是页面代码。
js部分用全选的:function All(e, itemName)
{
var aa = document.getElementsByName(itemName);
for (var i=0; i<aa.length; i++)
aa[i].checked = e.checked;//得到那个总控的复选框的选中状态
}
function Item(e, allName)
{
var all = document.getElementsByName(allName)[0];
if(!e.checked) all.checked = false;
else
{
var aa =document.getElementsByName(e.name);
for (vari=0; i<aa.length; i++)
if(!aa[i].checked) return;
all.checked= true;
}
}
php删除代码:
<?php
//连接数据库
include("conn.php");
//删除
//传来的值
$mm =$_POST["mm"];
$id=implode(",",$mm);
$sql ="delete from leaves where id in(".$id.")";
//echo$sql;
$result=mysql_query($sql);
echo$result?"删除成功":"删除失败";
?>
页面部分代码:
<table width="100%" border="0" cellspacing="0"cellpadding="0">
<tr>
<td height="20" bgcolor="#E5E6E7"class="114">
下面这句代码是注意看哦!
<input type="checkbox" name="mm[]"value="<?php echo $id; ?>"οnclick="Item(this, 'mmAll')">
<span class="block12">
网友
于
<?php echo $time;?>
</span>
</td>
<td bgcolor="#E5E6E7" align="right" width="10%"nowrap><ahref="admin_shanping_2.php?id=<?php echo $id;?>" οnclick="return confirm('您确定删除此项吗?')">删除</a>
<spanclass="block12">IP:<?php echo$Ip;?> </span></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"colspan=2>
<table width="100%" border="0" cellspacing="1"cellpadding="6" bgcolor="#D8D7D6">
<tr>
<td bgcolor="#FFFFFF"class="l14"><?php$content=htmlspecialchars($content,ENT_QUOTES); echo $content;?></td>
</tr>
</table>
</td>
</tr>
</table>
<?php
}
?>
</td>
</tr>
<tr>
<td align="center"><input type="checkbox" name="mmAll"οnclick="All(this, 'mm[]')">全选
<input name="Submit" type="submit"value="删除">
</tr>
</table>
js部分用全选的:function All(e, itemName)
{
var aa = document.getElementsByName(itemName);
for (var i=0; i<aa.length; i++)
}
function Item(e, allName)
{
var all = document.getElementsByName(allName)[0];
if(!e.checked) all.checked = false;
else
{
}
}
php删除代码:
<?php
//连接数据库
//删除
?>
页面部分代码:
<table width="100%" border="0" cellspacing="0"cellpadding="0">
<input type="checkbox" name="mm[]"value="<?php echo $id; ?>"οnclick="Item(this, 'mmAll')">
</tr>
<tr>
</tr>
</table>