jQuery+php簡單實現(xiàn)全選刪除的方法
本文實例講述了jQuery+php簡單實現(xiàn)全選刪除的方法。分享給大家供大家參考,具體如下:
<input type="checkbox" id="ckb_selectAll" onclick="selectAll()" title="選中/取消選中"> <a href="javascript:void(0);" onclick="del_()" title="刪除選定數(shù)據(jù)" style="font-weight:normal">刪除</a>
↑全選checkbox
<input type="checkbox" class="ckb" id="+con.id+" value="+con.id+">
↑為刪除項,同一命名class為ckb,方便操作,同時將id值巧妙的放入input中,方便獲取。
function selectAll() { if ($('#ckb_selectAll').is(':checked')) { $(".ckb").attr("checked", true); //全部選中 } else { $(".ckb").attr("checked", false);//全部取消 } }
↑選中事件
function del_() { var ids = ''; $(".ckb").each(function() { if ($(this).is(':checked')) { ids += ',' + $(this).val(); //逐個獲取id } }); ids = ids.substring(1); // 對id進行處理,去除第一個逗號 if (ids.length == 0) { alert('請選擇要刪除的選項'); } else { if (confirm("確定刪除?刪除后將無法恢復(fù)。")) { url = "action=del_call_record&ids=" + ids; $.ajax({ type: "post", url: "send.php", data: url, success: function(json) { if (parseInt(json.counts) > 0) { alert(json.des); location.reload(); } else { alert(json.des); } }, error: function(XMLHttpRequest, textStatus) { alert("頁面請求錯誤,請檢查重試或聯(lián)系管理員!\n" + textStatus); } }); } } }
↑刪除用ajax來處理。
↓后臺操作數(shù)據(jù)庫,處理刪除動作。
$ids = trim($_REQUEST['ids']); $del_sql = "DELETE FROM vicidial_call_record WHERE id IN(".$ids.")"; //print_r($del_sql);exit; if (mysqli_query($db_conn, $del_sql)) { $counts = "1"; $des = "成功"; } else { $counts = "0"; $des = "失敗"; } $json_data = "{"; $json_data. = "\"counts\":".json_encode($counts).","; $json_data. = "\"des\":".json_encode($des).""; $json_data. = "}"; echo $json_data; break;
完成
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP+ajax技巧與應(yīng)用小結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計有所幫助。
相關(guān)文章
詳解如何使用PHP實現(xiàn)動態(tài)代理IP的功能
動態(tài)代理IP是一種通過不斷切換不同的代理IP來隱藏真實IP地址的技術(shù),動態(tài)代理IP可以有效地解決IP被封鎖或訪問限制的問題,本文將使用PHP語言實現(xiàn)動態(tài)代理IP的功能,需要的朋友可以參考下2024-03-03php數(shù)組函數(shù)序列之a(chǎn)rray_splice() - 在數(shù)組任意位置插入元素
array_splice() 函數(shù)與 array_slice() 函數(shù)類似,選擇數(shù)組中的一系列元素,但不返回,而是刪除它們并用其它值代替2011-11-11