按钮全选

来源:互联网 发布:ds18b20与单片机连接图 编辑:程序博客网 时间:2024/05/27 16:40

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>无标题文档</title>

<script type="text/javascript">

function CheckAll(delid,checkMoreId){

for(i=0;i<delid.length;i++){

   delid[i].checked = true;

}

if(checkMoreId.checked ==false){

   for(j=0;j<delid.length;j++){

    delid[j].checked = false;

   }

}

}

//判断用户是否选择了要删除的记录,如果是,则提示“是否删除”;否则提示“请选择要删除的记录”

function checkdel(delid,formname){

var flag = false;

for(i=0;i<delid.length;i++){

   if(delid[i].checked == true){

    flag = true;

    break;

   }

}

if(!flag){

   alert("请选择要删除的记录!");

  

   return false;

}

else{

    if(confirm("确定要删除吗?")){

     formname.submit();

   }

}

}

function delOrtrue()

{

           if(confirm("确定要删除这条记录吗?"))

           {

     return true;

           }

           else

           {

              return false;

           }

    }

</script>

</head>

<body>

<form action="out.php" method="post" name="check">


<input type="checkbox" name="del_id[]" value="1" id="del_id" />

<input type="checkbox" name="del_id[]" value="2" id="del_id" />

<input type="checkbox" name="del_id[]" value="3" id="del_id" />

<input type="checkbox" name="del_id[]" value="4" id="del_id" />

删除

<input type="submit" name="delete" value="删除" onclick="javascript:if(checkdel(del_id,'check')){return true;}else{return false;};" />

</form>

</body>

</html>

out.php

<?php

if(isset($_POST["delete"]) && isset($_POST["del_id"]))

{

$ids = array();

$ids = $_POST['del_id'];

if($ids)

{

foreach($ids as $id)

{

   $tmp[] = intval($id);

}

$ids = $tmp;

}

$ids = implode(',',$ids);

echo($ids);

//$sql_delbook = "delete from guestbook where id in ($ids)";

//$result = $db->db_query($sql_delbook);

}

else{

$msg ="请选择要删除的记录!";

$url ="checkmost.php";

echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" />";

   echo("<script language='JavaScript'>");

   if ($msg != "") { echo("alert('$msg');"); }

   echo("window.location = '$url';");

   echo("</script>");

   exit;

}


?>

 

 

 

*********************************************

 

php 的批量删除

 

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 (var i=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; ?>" onclick="Item(this, 'mmAll')">
            <span class="block12">
              网友
              于
              <?php echo $time; ?>       
               </span>
            </td>
            <td bgcolor="#E5E6E7" align="right" width="10%" nowrap><a href="admin_shanping_2.php?id=<?php echo $id; ?>" onclick="return confirm('您确定删除此项吗?')" >删除</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <span class="block12">IP:<?php echo $Ip;?>&nbsp;</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" onclick="All(this, 'mm[]')">全选 &nbsp;&nbsp;
    <input name="Submit" type="submit" value="删除">&nbsp;&nbsp;&nbsp;
</tr>
</table>

 

***************************************************

 

批量删除

批量删除文章这个技术没什么高深莫测的,只是想写下来与大家分享。(适合初学者:)
php批量删除数据,php删除多项数据


1、首先在文章列表页面(list.php),将多选筐命名为:“$del_id[]”,值为文章ID号。
     例如(list.php):
<form name="del_form" action="del.php" method="post">
<?php
        $result=mysql_query("select * from news");
        while($rs=mysql_fetch_array($result)){
     ?>
        <input name="del_id[]" type="checkbox" id="del_id[]" value="<?=$rs[id]?>" /><?=$rs[title]?>
     <?php
        }
     ?>
   </form>


2、处理页面(del.php):


<?php
include"conn.php";

$array = $_POST["del_id"];       //将所选的值组成的数组放入$array数组

if(!empty($array)){

$del_num=count($array);
for($ii=0;$ii<$del_num;$ii++){
mysql_query("Delete from liuyan where id=$array[$ii]");
}
echo("<script type='text/javascript'>alert('删除成功!');history.back();</script>");
}else{
echo("<script type='text/javascript'>alert('请先选择项目!');history.back();</script>");
}

?>


***********************************************************************

批量删除

html 代码

<form name="del_form" action="del.php?post=all" method="post">

<tr><td><input name="del_id[]" type="checkbox" id="del_id[]" value="<?echo $id ?>" onclick="checkItem(this, 'del_idAll')"/><a href="../htm/<? echo $folder ?>/<? echo $article_id ?>.html" target="_blank"><? echo $content ?></a></td><td><?echo $article_id ?></td><td><? echo $username ?></td><td><? echo $date ?></td><td>否</td><td><a href="#">[编辑]</a> <a href="../include/del.php?field=id&db_table=lw_comment&id=<? echo $id ?>&page=../leave/index.php" onclick="return confirm('确定del?')">[删除]</a> </td></tr>

<input type=checkbox name=mmAll onclick="checkAll(this, 'del_id[]')">全选与不全选的切换

    <INPUT class="inputbut" id="b1" onclick="SelAll(this, 'del_id[]')" type="button" value="全选" name="mmAll">

    <INPUT class="inputbut" id="b1" onclick="ReSel(this, 'del_id[]')" type="button" value="反选" name="mmAll">

    <INPUT class="inputbut" id="b1" onclick="NoneSel(this, 'del_id[]')" type="button" value="取消" name="mmAll">

   <input type="submit" name="B2" value="批量删除" onclick="return confirm('确定del?')"/>

      </form>

php代码

if($_GET[post] == all)

{

if($_POST[del_id]!="")

{

             $del_num=count($_POST[del_id]);

             $del_id=$_POST[del_id];

             for($i=0;$i<$del_num;$i++){

                 mysql_query("Delete from lw_comment where id='$del_id[$i]'");

                 echo "删除 $del_id[$i]";

             }

             echo "<meta http-equiv='Refresh' content='0;URL=index.php'>";

      }else{

             echo("<script type='text/javascript'>alert('请先选择项目!');history.back();</script>");

      }

}else{

del("$_GET[db_table]","$_GET[field]","$_GET[id]","$_GET[page]");

}

原创粉丝点击