jQuery+ajax實現(xiàn)批量刪除功能完整示例
本文實例講述了jQuery+ajax實現(xiàn)批量刪除功能。分享給大家供大家參考,具體如下:
效果展示:
完整代碼如下:
<!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 rel="external nofollow" rel="stylesheet"> <link 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' >標(biāo)題</th> </tr> </thead> <tbody> <tr> <td><input type="checkbox" value="10001"></td> <td>10001</td> <td >標(biāo)題1</td> </tr> <tr> <td><input type="checkbox" value="10002"></td> <td>10002</td> <td >標(biāo)題2</td> </tr> <tr> <td><input type="checkbox" value="10003"></td> <td>10003</td> <td >標(biāo)題3</td> </tr> <tr> <td><input type="checkbox" value="10004"></td> <td>10004</td> <td >標(biāo)題4</td> </tr> <tr> <td><input type="checkbox" value="10005"></td> <td>10005</td> <td >標(biāo)題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根據(jù)自己的情況寫 layer.confirm('批量刪除后不可恢復(fù),謹(jǐn)慎操作!', {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代碼運(yùn)行工具:http://tools.jb51.net/code/HtmlJsRun測試上述代碼運(yùn)行效果。
更多關(guān)于jQuery相關(guān)內(nèi)容可查看本站專題:《jquery中Ajax用法總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery常見經(jīng)典特效匯總》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計有所幫助。
- jQuery+Ajax+js實現(xiàn)請求json格式數(shù)據(jù)并渲染到html頁面操作示例
- JQuery發(fā)送ajax請求時中文亂碼問題解決
- jQuery實現(xiàn)form表單基于ajax無刷新提交方法實例代碼
- php+jQuery ajax實現(xiàn)的實時刷新顯示數(shù)據(jù)功能示例
- jquery+ajax實現(xiàn)上傳圖片并顯示上傳進(jìn)度功能【附php后臺接收】
- jquery實現(xiàn)Ajax請求的幾種常見方式總結(jié)
- PHP結(jié)合jquery ajax實現(xiàn)上傳多張圖片,并限制圖片大小操作示例
- Jquery ajax書寫方法代碼實例解析
相關(guān)文章
ASP.NET jQuery 實例1(在TextBox里面創(chuàng)建一個默認(rèn)提示)
通常用戶在搜索內(nèi)容時,在文本框輸入內(nèi)容前,文本框都會給出默認(rèn)提示,提示用戶輸入正確的內(nèi)容進(jìn)行搜索2012-01-01解析jQuery的三種bind/One/Live事件綁定使用方法
本篇文章主要是對jQuery的三種bind/One/Live事件綁定使用方法進(jìn)行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助2013-12-12jquery easyui 結(jié)合jsp簡單展現(xiàn)table數(shù)據(jù)示例
這篇文章主要介紹了jquery easyui 結(jié)合jsp簡單展現(xiàn)table數(shù)據(jù),需要的朋友可以參考下2014-04-04jQuery實現(xiàn)下拉菜單(內(nèi)容為時間)的實時更新及圖表的隨動更新的方法
這篇文章主要介紹了實現(xiàn)下拉菜單(內(nèi)容為時間)的實時更新及圖表的隨動更新的方法的相關(guān)資料,需要的朋友可以參考下2016-07-07jQuery插件開發(fā)精品教程讓你的jQuery提升一個臺階
這篇文章主要介紹了jQuery插件開發(fā)精品教程讓你的jQuery提升一個臺階 的相關(guān)資料,需要的朋友可以參考下2016-01-01