国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 池州市| 香格里拉县| 延寿县| 定安县| 安仁县| 兴城市| 德清县| 晋城| 青河县| 五华县| 当雄县| 获嘉县| 榆中县| 抚松县| 岗巴县| 邵武市| 措勤县| 积石山| 科技| 新余市| 桂平市| 峨边| 资中县| 信丰县| 巴彦淖尔市| 岱山县| 积石山| 清水河县| 乃东县| 兰州市| 商洛市| 昌黎县| 和林格尔县| 固始县| 遵化市| 文安县| 石家庄市| 莱芜市| 读书| 金山区| 许昌市|