天天看点

checkbox批量全选操作

 form 中checkbox批量全选操作

<a href="http://blog.51cto.com/attachment/201302/124713349.jpg" target="_blank"></a>

&lt;?php 

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

    $ids = array(); 

    $ids = $_POST['del_id']; 

    $update_page=$_POST['update_page']; 

    include("conn.php"); 

    if($ids){ 

        foreach($ids as $id){ 

            $sql05="update `table` set `is_verify`='1' where `id`='$id';"; 

            mysql_query($sql05,$conn); 

           //$tmp[] = intval($id); 

        } 

        //$ids = $tmp; 

    } 

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

    echo "&lt;script&gt;alert('批量审核通过成功!');window.location='list.php?page=".$update_page."'&lt;/script&gt;"; 

?&gt; 

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; 

&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; 

&lt;head&gt; 

&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt; 

&lt;title&gt;form批量操作&lt;/title&gt; 

&lt;script type="text/javascript" src="jquery.min.js"&gt;&lt;/script&gt; 

&lt;script type="text/javascript" src="ddaccordion.js"&gt;&lt;/script&gt; 

&lt;script type="text/javascript"&gt; 

//Initialize Arrow Side Menu: 

ddaccordion.init({ 

    headerclass: "menuheaders", //Shared CSS class name of headers group 

    contentclass: "menucontents", //Shared CSS class name of contents group 

    revealtype: "clickgo", //Reveal content when user clicks or onmouseover the header? Valid value: "click", or "mouseover" 

    mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover 

    collapseprev: true, //Collapse previous content (so only one open at any time)? true/false  

    defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc]. [] denotes no content. 

    onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed) 

    animatedefault: false, //Should contents open by default be animated into view? 

    persiststate: true, //persist state of opened contents within browser session? 

    toggleclass: ["unselected", "selected"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"] 

    togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs) 

    animatespeed: 500, //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow" 

    oninit:function(expandedindices){ //custom code to run when headers have initalized 

        //do nothing 

    }, 

    onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed 

}) 

&lt;/script&gt; 

function CheckAll(delid,checkMoreId){ 

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

   delid[i].checked = true; 

if(checkMoreId.checked ==false){ 

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

    delid[j].checked = false; 

   } 

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

function checkdel(delid,formname){ 

var flag = false; 

   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; 

&lt;/head&gt; 

&lt;body&gt; 

&lt;form action="" method="post" name="check"&gt; 

    &lt;table&gt; 

        &lt;tr&gt; 

            &lt;td&gt;&lt;input type="checkbox" name="del_id[]" value="1" id="del_id" /&gt;one&lt;/td&gt; 

        &lt;/tr&gt; 

            &lt;td&gt;&lt;input type="checkbox" name="del_id[]" value="2" id="del_id" /&gt;two&lt;/td&gt; 

            &lt;td&gt;&lt;input type="checkbox" name="del_id[]" value="3" id="del_id" /&gt;three&lt;/td&gt; 

            &lt;td&gt; 

                &lt;input type="checkbox" name="role_id" id="selectAll" onclick="CheckAll(del_id,selectAll)" value="2"/&gt;全选 

                &lt;input type="submit" name="delete" value="批量通过审核" onclick="if(checkdel(del_id,'check')){return true;}else{return false;};"&lt; /span&gt; /&gt; 

            &lt;/td&gt; 

    &lt;/table&gt; 

&lt;/form&gt; 

&lt;/body&gt; 

&lt;/html&gt; 

源码下载地址:

<a href="http://down.51cto.com/data/679335" target="_blank">http://down.51cto.com/data/679335</a>

      本文转自许琴 51CTO博客,原文链接:http://blog.51cto.com/xuqin/1131653,如需转载请自行联系原作者

继续阅读