checkbox批量刪除js(全選/全部選)

  1. <script type="text/javascript">  
  2.     function seltAll(){  
  3.         var chckBoxSign = document.getElementById("ckb");       //ckb 全選/反選的選擇框id  
  4.         var chckBox = document.getElementsByName("chckBox");    //所有的選擇框其那麼都是chckBox  
  5.         var num = chckBox.length;  
  6.         if(chckBoxSign.checked){  
  7.             for(var index =0 ; index<num ; index++){  
  8.                 chckBox[index].checked = true;  
  9.                 }  
  10.         }else{  
  11.             for(var index =0 ; index<num ; index++){  
  12.                 chckBox[index].checked = false;  
  13.                 }  
  14.             }  
  15.         }  
  16.   
  17.     function deleSeltedRecords(){  
  18.         var chckBox = document.getElementsByName("chckBox");  
  19.         var num = chckBox.length;  
  20.         var ids = "";  
  21.         for(var index =0 ; index<num ; index++){  
  22.             if(chckBox[index].checked){  
  23.                 ids += chckBox[index].value + ",";                
  24.             }  
  25.         }  
  26.         if(ids!=""){  
  27.             if(window.confirm("確定刪除所選記錄?")){  
  28.                 $.ajax( {  
  29.                     type : "post",  
  30.                     url : '../g3/history-no!batchDelete.action?ids=' + ids, //要自行刪除的action  
  31.                     dataType : 'json',  
  32.                     success : function(data) {  
  33.                         alert("刪除成功");  
  34.                         window.location.href = "channel-no.action" ;  
  35.                     },  
  36.                     error : function(data) {  
  37.                         alert("系統錯誤,刪除失敗");  
  38.                     }  
  39.                 });  
  40.             }  
  41.         }else{  
  42.             alert("請選擇要刪除的記錄");  
  43.             }  
  44.         }  
  45. </script> 
發佈了43 篇原創文章 · 獲贊 28 · 訪問量 27萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章