js:
<script language=javascript>//选中全选按钮,下面的checkbox全部选中 var selAll = document.getElementById("selAll"); function selectAll() { var obj = document.getElementsByName("id[]"); if(document.getElementById("selAll").checked == false){ for(var i=0; i<obj.length; i++){ obj[i].checked=false; } }else{ for(var i=0; i<obj.length; i++){ obj[i].checked=true; } }}</script>
复制代码
html:
<form name="form1" id="form1" action="forum_del.php" method="post"> <article class="module width_3_quarter"> <header><h3 class="tabs_involved">版块列表</h3> <input type="checkbox" id="selAll" style="margin-top:8px;" onclick="selectAll();" />全选 <input type="submit" name="del" value="删除" class="alt_btn" > <input type="button" value="添加" class="alt_btn" > <input type="button" value="合并" class="alt_btn" > </header> <div class="tab_container"> <div id="tab1" class="tab_content"> <table class="tablesorter" cellspacing="0"> <thead> <tr> <th></th> <th>排序号</th> <th>名称</th> <th>创建时间</th> <th>修改时间</th> <th>操作</th> </tr> </thead> <tbody> <?php require('fourm_list.php'); ?> <?php foreach($forumlist as $v){ ?> <tr> <td><input type="checkbox" name="id[]" value="<?php echo $v['sid'];?>"/></td> <td><?php echo $v['ordernum']; ?></td> <td><?php echo $v['sname']; ?></td> <td><?php echo $v['createtime']; ?></td> <td><?php echo $v['updatetime']; ?></td> <td> <input type="image" src="../view/admin/images/icn_edit.png" title="编辑"> <input type="image" src="../view/admin/images/icn_trash.png" title="删除"> <input type="image" src="../view/admin/images/icn_categories.png" title="详细"> </td> </tr> <?php } ?> </tbody> </table> </div> </div> </article></form>
复制代码
fourm_list.php
<?php$forum = new forumModel();$forumlist = $forum->select();
复制代码fourm_del.php
<?phpdefine('ACC',true);require('../include/init.php');$fourm = new forumModel();if(isset($_GET['del'])){if(!empty($_GET['id'])){$id=$_GET['id'];foreach($id as $n){ $fourm->delete($n);} echo("<script type='text/javascript'>alert('删除成功!');location.replace(document.referrer);</script>");}else{echo("<script type='text/javascript'>alert('请先选择版块!');location.replace(document.referrer);</script>");}}
复制代码
<script language=javascript>//选中全选按钮,下面的checkbox全部选中 var selAll = document.getElementById("selAll"); function selectAll() { var obj = document.getElementsByName("id[]"); if(document.getElementById("selAll").checked == false){ for(var i=0; i<obj.length; i++){ obj[i].checked=false; } }else{ for(var i=0; i<obj.length; i++){ obj[i].checked=true; } }}</script>
复制代码
html:
<form name="form1" id="form1" action="forum_del.php" method="post"> <article class="module width_3_quarter"> <header><h3 class="tabs_involved">版块列表</h3> <input type="checkbox" id="selAll" style="margin-top:8px;" onclick="selectAll();" />全选 <input type="submit" name="del" value="删除" class="alt_btn" > <input type="button" value="添加" class="alt_btn" > <input type="button" value="合并" class="alt_btn" > </header> <div class="tab_container"> <div id="tab1" class="tab_content"> <table class="tablesorter" cellspacing="0"> <thead> <tr> <th></th> <th>排序号</th> <th>名称</th> <th>创建时间</th> <th>修改时间</th> <th>操作</th> </tr> </thead> <tbody> <?php require('fourm_list.php'); ?> <?php foreach($forumlist as $v){ ?> <tr> <td><input type="checkbox" name="id[]" value="<?php echo $v['sid'];?>"/></td> <td><?php echo $v['ordernum']; ?></td> <td><?php echo $v['sname']; ?></td> <td><?php echo $v['createtime']; ?></td> <td><?php echo $v['updatetime']; ?></td> <td> <input type="image" src="../view/admin/images/icn_edit.png" title="编辑"> <input type="image" src="../view/admin/images/icn_trash.png" title="删除"> <input type="image" src="../view/admin/images/icn_categories.png" title="详细"> </td> </tr> <?php } ?> </tbody> </table> </div> </div> </article></form>
复制代码
fourm_list.php
<?php$forum = new forumModel();$forumlist = $forum->select();
复制代码fourm_del.php
<?phpdefine('ACC',true);require('../include/init.php');$fourm = new forumModel();if(isset($_GET['del'])){if(!empty($_GET['id'])){$id=$_GET['id'];foreach($id as $n){ $fourm->delete($n);} echo("<script type='text/javascript'>alert('删除成功!');location.replace(document.referrer);</script>");}else{echo("<script type='text/javascript'>alert('请先选择版块!');location.replace(document.referrer);</script>");}}
复制代码
<input type="checkbox" name="id[]" value="<?php echo $v['sid'];?>"/>
吗?
提交后 $_POST['id'] 数组中不就是要删除的 sid 吗?