三步搞定全选删除
//action中调用
$user=M('User');
$base=A('Base');
$user->deleteall($staff);
//全选删除函数
public function deleteall($mouldel){
@extract($_POST);
$counts=count($id);
for($i=0;$i<=$counts;$i++)
{
$mouldel->where('id="'.$id[$i].'"')->delete();
}
if($counts)
{
$this->success("删除成功");
}
else
{
$this->error("删除失败");
}
}
模板中js部分
function unselectall(){
if(document.myform.chkAll.checked){
document.myform.chkAll.checked = document.myform.chkAll.checked&0;
}
}
function CheckAll(form){
for (var i=0;i<form.elements.length;i++){
var e = form.elements[i];
if (e.Name != 'chkAll'&&e.disabled==false)
e.checked = form.chkAll.checked;
}
}
html
<form>
<table><tr>
<td>删除</td>
</tr>
<tr><input type="checkbox" name="id[]" value="{$vo.id}"/></tr>
<tr><input type="checkbox" id='chkAll' onclick='CheckAll(this.form)' value="全选"/></tr>
</table>
</form>