国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jQuery+ajax實現(xiàn)批量刪除功能完整示例

2019-11-19 11:23:00
字體:
供稿:網(wǎng)友

本文實例講述了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' >標題</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根據(jù)自己的情況寫    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.VeVB.COm/code/HtmlJsRun測試上述代碼運行效果。

更多關(guān)于jQuery相關(guān)內(nèi)容可查看本站專題:《jquery中Ajax用法總結(jié)》、《jQuery擴展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery常見經(jīng)典特效匯總》及《jquery選擇器用法總結(jié)

希望本文所述對大家jQuery程序設計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 电白县| 甘南县| 上林县| 昔阳县| 含山县| 岑巩县| 乐清市| 泗阳县| 大理市| 江西省| 贵阳市| 山西省| 龙南县| 宜都市| 贵港市| 大方县| 万山特区| 通州区| 习水县| 新沂市| 扬中市| 建水县| 辽宁省| 修文县| 永德县| 香河县| 西和县| 兰溪市| 庆安县| 洛隆县| 米泉市| 塔城市| 教育| 运城市| 区。| 拜城县| 抚州市| 高密市| 高阳县| 方正县| 禄劝|