php+ajax簡單實現(xiàn)全選刪除的方法
本文實例講述了php+ajax簡單實現(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("確定刪除?刪除后將無法恢復。")) {
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技巧與應用小結(jié)》、《PHP網(wǎng)絡編程技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O計入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設計有所幫助。
- 基于php(Thinkphp)+jquery 實現(xiàn)ajax多選反選不選刪除數(shù)據(jù)功能
- PHP+ajax 無刷新刪除數(shù)據(jù)
- PHP jQuery+Ajax結(jié)合寫批量刪除功能
- ajax php實現(xiàn)給fckeditor文本編輯器增加圖片刪除功能
- thinkPHP利用ajax異步上傳圖片并顯示、刪除的示例
- PHP ajax+jQuery 實現(xiàn)批量刪除功能實例代碼小結(jié)
- php采用ajax數(shù)據(jù)提交post與post常見方法總結(jié)
- ajax處理php返回json數(shù)據(jù)的實例代碼
- Ajax+PHP實現(xiàn)的刪除數(shù)據(jù)功能示例
相關(guān)文章
PHP Swoole異步Redis客戶端實現(xiàn)方法示例
這篇文章主要介紹了PHP Swoole異步Redis客戶端實現(xiàn)方法,結(jié)合實例形式詳細分析了php操作Swoole異步Redis客戶端相關(guān)擴展安裝與功能實現(xiàn)技巧,需要的朋友可以參考下2019-10-10
詳解WordPress中調(diào)用評論模板和循環(huán)輸出評論的PHP函數(shù)
這篇文章主要介紹了WordPress中調(diào)用評論模板和循環(huán)輸出評論的PHP函數(shù),分別是comments_template函數(shù)與wp_list_comments函數(shù)的使用,需要的朋友可以參考下2016-01-01
php通過curl方式實現(xiàn)發(fā)送接收xml數(shù)據(jù)
這篇文章主要為大家詳細介紹了php如何通過curl方式實現(xiàn)發(fā)送接收xml數(shù)據(jù),文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下2023-11-11
php5.2以下版本無json_decode函數(shù)的解決方法
這篇文章主要介紹了php5.2以下版本無json_decode函數(shù)的解決方法,需要的朋友可以參考下2014-05-05
如何從一個php文件向另一個地址post數(shù)據(jù),不用表單和隱藏的變量的
如何從一個php文件向另一個地址post數(shù)據(jù),不用表單和隱藏的變量的...2007-03-03

