jQuery+ajax实现批量删除功能完整示例


Posted in jQuery onJune 06, 2019

本文实例讲述了jQuery+ajax实现批量删除功能。分享给大家供大家参考,具体如下:

效果展示:

jQuery+ajax实现批量删除功能完整示例

完整代码如下:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
  <title>Ding Jianlong Html</title>
  <link href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="external nofollow" rel="stylesheet">
  <link href="https://cdn.bootcss.com/layer/2.4/skin/layer.min.css" rel="external nofollow" rel="stylesheet">
</head>
<body>
 <div class="container">
 <button class="btn btn-danger radius" onClick="batch_del()" style='margin:10px;'>批量删除</button>
   <table style="width: 500px;" class="table table-striped table-hover table-bordered">
  <thead>
  <tr>
   <th scope='col' width="25"><input type="checkbox" value="" name="selectall"></th>
   <th scope='col' width="80">ID</th>
   <th scope='col' >标题</th>
  </tr>
  </thead>
  <tbody>
  <tr>
   <td><input type="checkbox" value="10001"></td>
   <td>10001</td>
   <td >标题1</td>
  </tr>
  <tr>
   <td><input type="checkbox" value="10002"></td>
   <td>10002</td>
   <td >标题2</td>
  </tr>
  <tr>
   <td><input type="checkbox" value="10003"></td>
   <td>10003</td>
   <td >标题3</td>
  </tr>
  <tr>
   <td><input type="checkbox" value="10004"></td>
   <td>10004</td>
   <td >标题4</td>
  </tr>
  <tr>
   <td><input type="checkbox" value="10005"></td>
   <td>10005</td>
   <td >标题5</td>
  </tr>
  </tbody>
 </table>
 </div>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<script src="https://cdn.bootcss.com/layer/2.4/layer.min.js"></script>
<script>
 /*批量选中的效果*/
 $('input:checkbox[name="selectall"]').click(function(){
 if($(this).is(':checked')){
     $('input:checkbox').each(function(){
    $(this).prop("checked",true);
  });
    }else{
      $('input:checkbox').each(function(){
    $(this).prop("checked",false);
  });
    }
 });
 /*获取ids,批量删除*/
  function batch_del() {
    var ids = '';
    $('input:checkbox').each(function(){
      if(this.checked == true){
        ids += this.value + ',';
      }
    });
    //layer.alert(ids);return;
    //下面的ajax根据自己的情况写
    layer.confirm('批量删除后不可恢复,谨慎操作!', {icon: 7, title: '警告'}, function (index) {
      $.ajax({
        type: 'POST',
        url: '你的url地址?ids=' + ids,
        data: {"1": "1"},
        dataType: 'json',
        success: function (data) {
          if (data.code == 200) {
            $(obj).parents("tr").remove();
            layer.msg(data.message, {icon: 1, time: 1000});
          } else {
            layer.msg(data.message, {icon: 2, time: 3000});
          }
        },
        error: function (data) {
          console.log(data.msg);
        },
      });
    });
  }
</script>
</body>
</html>

感兴趣的朋友可以使用在线HTML/CSS/JavaScript代码运行工具:http://tools.3water.com/code/HtmlJsRun测试上述代码运行效果。

更多关于jQuery相关内容可查看本站专题:《jquery中Ajax用法总结》、《jQuery扩展技巧总结》、《jQuery常用插件及用法总结》、《jQuery常见经典特效汇总》及《jquery选择器用法总结》

希望本文所述对大家jQuery程序设计有所帮助。

jQuery 相关文章推荐
jQuery判断邮箱格式对错实例代码讲解
Apr 12 jQuery
解决jQuery ajax动态新增节点无法触发点击事件的问题
May 24 jQuery
jQuery正则验证注册页面经典实例
Jun 10 jQuery
jQuery DOM节点的遍历方法小结
Aug 15 jQuery
使用jQuery实现两个div中按钮互换位置的实例代码
Sep 21 jQuery
jquery的 filter()方法使用教程
Mar 22 jQuery
jQuery中将json数据显示到页面表格的方法
May 27 jQuery
js与jQuery实现获取table中的数据并拼成json字符串操作示例
Jul 12 jQuery
在vue项目中使用Jquery-contextmenu插件的步骤讲解
Jan 27 jQuery
AJAX在JQuery中的应用详解
Jan 30 jQuery
JQuery事件委托原理与用法实例分析
May 13 jQuery
JS+JQuery实现无缝连接轮播图
Dec 30 jQuery
jquery+ajax实现上传图片并显示上传进度功能【附php后台接收】
Jun 06 #jQuery
jQuery操作cookie的示例代码
Jun 05 #jQuery
jquery UI实现autocomplete在获取焦点时得到显示列表功能示例
Jun 04 #jQuery
javascript异步处理与Jquery deferred对象用法总结
Jun 04 #jQuery
一文快速了解JQuery中的AJAX
May 31 #jQuery
jQuery实现动态加载(按需加载)javascript文件的方法分析
May 31 #jQuery
jQuery模拟html下拉多选框的原生实现方法示例
May 30 #jQuery
You might like
做个自己站内搜索引擎
2006/10/09 PHP
计算一段日期内的周末天数的php代码(星期六,星期日总和)
2009/11/12 PHP
PHP简单读取PDF页数的实现方法
2016/07/21 PHP
PHP使用FFmpeg获取视频播放总时长与码率等信息
2016/09/13 PHP
通过PHP设置BugFree获取邮箱通知
2019/04/25 PHP
php获取微信openid方法总结
2019/10/10 PHP
PHP pthreads v3下的Volatile简介与使用方法示例
2020/02/21 PHP
jQuery EasyUI NumberBox(数字框)的用法
2010/07/08 Javascript
使用Jquery搭建最佳用户体验的登录页面之记住密码自动登录功能(含后台代码)
2011/07/10 Javascript
js跨浏览器实现将字符串转化为xml对象的方法
2013/09/25 Javascript
什么是cookie?js手动创建和存储cookie
2014/05/27 Javascript
轻量级javascript 框架Backbone使用指南
2015/07/24 Javascript
简要了解jQuery移动web开发的响应式布局设计
2015/12/04 Javascript
JS中事件冒泡和事件捕获介绍
2016/12/13 Javascript
详解jQuery中基本的动画方法
2016/12/14 Javascript
Nodejs+Socket.io实现通讯实例代码
2017/02/13 NodeJs
最通俗易懂的javascript变量提升详解
2017/08/05 Javascript
JS非行间样式获取函数的实例代码
2018/06/05 Javascript
使用jQuery给Table动态增加行、清空table的方法
2018/09/05 jQuery
ES6对象操作实例详解
2020/05/23 Javascript
使用python进行文本预处理和提取特征的实例
2018/06/05 Python
python3.6.3转化为win-exe文件发布的方法
2018/10/31 Python
Python中turtle库的使用实例
2019/09/09 Python
Python提取视频中图片的示例(按帧、按秒)
2020/10/22 Python
python import 上级目录的导入
2020/11/03 Python
canvas绘制表情包的示例代码
2018/07/09 HTML / CSS
英国的屈臣氏:Boots博姿
2017/12/23 全球购物
介绍一下SQL注入攻击的种类和防范手段
2012/02/18 面试题
热能动力工程毕业生自荐信
2013/11/07 职场文书
小学生学习感言
2014/03/10 职场文书
大班下学期个人总结
2015/02/13 职场文书
单位实习介绍信
2015/05/05 职场文书
离婚案件答辩状
2015/05/22 职场文书
优秀学生主要事迹怎么写
2015/11/04 职场文书
mybatis使用oracle进行添加数据的方法
2021/04/27 Oracle
vue.js Router中嵌套路由的实用示例
2021/06/27 Vue.js