Home >Backend Development >PHP Tutorial >新手求指教!jQuery实现全选与批量删除?该如何解决

新手求指教!jQuery实现全选与批量删除?该如何解决

WBOY
WBOYOriginal
2016-06-13 10:22:50970browse

新手求指教!jQuery实现全选与批量删除??
这是数据库循环取出来的ID



这是几个button



 

这是全选与反转代码
$(function(){

  $("#checkedAll").click(function(){
$("[name=check]:checkbox").attr('checked',true);
});

$("#checkedRev").click(function(){
$("[name=check]:checkbox").each(function(){
this.checked=!this.checked;
});
});

});

但怎样实现批量删除??求高手指教!! 先谢啦!!


------解决方案--------------------

------解决方案--------------------
PHP code
<?phpif ($_SERVER['REQUEST_METHOD'] === "POST"){    foreach($_POST as $chk => $post){         $pos = strpos($chk,"check");        if(!$pos === false)            $ids[] = $post;    }    if(count($ids) > 1)        $id = implode(",",$ids);    else        $id = implode($ids);    $sql = "DELETE FROM [table] WHERE id IN (".$id.")";    $result = mysql_query($sql,$conn);    if(!$result)              die("SQL: {$sql} <br>Error: " . mysql_error() );    if(mysql_affected_rows() > 0)        echo "<script>alert('已批量删除');</script>";    else        echo "<script>alert('批量删除失败\nError:".mysql_error()."');</script>";}?><?php foreach($rows as $row){ ?><td><input type="checkbox" name="check[]" value="<?php echo $row['adm_id'] ?>"></td><?php } ?><div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn