欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP批量刪除jQuery操作

 更新時(shí)間:2017年07月23日 09:02:41   作者:腳步6978  
這篇文章主要介紹了PHP批量刪除jQuery操作,非常不錯,具有慘借鑒價(jià)值,需要的朋友可以參考下

效果圖如下所述:

這里寫圖片描述—>—>—>這里寫圖片描述
這里寫圖片描述—>—>—>這里寫圖片描述

創(chuàng)建視圖show.php

<?php 
 header('content-type:text/html;charset=utf-8');
 $pdo=new PDO('mysql:host=localhost;dbname=***;','root','root');
 $pdo->exec('set names utf8');
 $sql='select * from ***';
 $info=$pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
?>
<center>
<table border="1">
 <tr>
  <td>id</td>
  <td>title</td>
  <td>content</td>
 </tr>
 <?php foreach($info as $k => $v){ ?>
 <tr>
  <td><input type="checkbox" name="box" value="<?= $v['id'] ?>"><?= $v['id'] ?></td>
  <td><?= $v['title'] ?></td>
  <td><?= $v['content'] ?></td>
 </tr>
 <?php } ?>
</table>
 <button>批量刪除</button>
</center>
<script src="../jquery.1.12.min.js"></script>
<script>
 $(function(){
  $('button').click(function(){
   var ids=$(':checkbox');
   var str='';
   var count=0;
   for(var i=0;i<ids.length;i++){
    if(ids.eq(i).is(':checked')){
     str+=','+ids.eq(i).val();
     count++;
    }
   }
   var str=str.substr(1);
   if(confirm('你確定要刪除這'+count+'條數(shù)據(jù)嗎?')){
    //獲取id后刪除
    $.ajax({
     type:'get',
     url:'adminDel.php',
     data:{str:str},
     success:function(res){
      if(res>0){
       alert('刪除成功');
       for(var i=ids.length-1;i>=0;i--){
        if(ids.eq(i).is(':checked')){
         ids.eq(i).parent().parent().remove();
        }
       }
      }
     }
    })
   }
   return false;
   /*var box=document.getElementsByName('box');
   var str="";
   for(var i=0;i<box.length;i++){
    if(box[i].checked==true){
     str+=','+box[i].value;
    }
   }
   var str=str.substr(1);
   alert(str);*/
  });
 })
</script>

創(chuàng)建adminDel.php

<?php 
 header('content-type:text/html;charset=utf-8');
 $str=$_GET['str'];
 $pdo=new PDO('mysql:host=localhost;dbname=***;','root','root');
 $pdo->exec('set names utf8');
 $sql='delete from *** where id in ('.$str.')';
 $res=$pdo->exec($sql);
 //受影響行數(shù)
 echo $res;
?>

以上所述是小編給大家介紹的PHP批量刪除jQuery操作,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時(shí)回復(fù)大家的。

相關(guān)文章

最新評論