jQuery+php簡(jiǎn)單實(shí)現(xiàn)全選刪除的方法
本文實(shí)例講述了jQuery+php簡(jiǎn)單實(shí)現(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+">
↑為刪除項(xiàng),同一命名class為ckb,方便操作,同時(shí)將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(); //逐個(gè)獲取id
}
});
ids = ids.substring(1); // 對(duì)id進(jìn)行處理,去除第一個(gè)逗號(hào)
if (ids.length == 0) {
alert('請(qǐng)選擇要?jiǎng)h除的選項(xiàng)');
} 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("頁(yè)面請(qǐng)求錯(cuò)誤,請(qǐng)檢查重試或聯(lián)系管理員!\n" + textStatus);
}
});
}
}
}
↑刪除用ajax來處理。
↓后臺(tái)操作數(shù)據(jù)庫(kù),處理刪除動(dòng)作。
$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è)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見數(shù)據(jù)庫(kù)操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
- jQuery ajax+PHP實(shí)現(xiàn)的級(jí)聯(lián)下拉列表框功能示例
- PHP ajax+jQuery 實(shí)現(xiàn)批量刪除功能實(shí)例代碼小結(jié)
- PHP批量刪除jQuery操作
- PHP jQuery+Ajax結(jié)合寫批量刪除功能
- jQuery+ThinkPHP+Ajax實(shí)現(xiàn)即時(shí)消息提醒功能實(shí)例代碼
- php+mysql+jquery實(shí)現(xiàn)日歷簽到功能
- thinkphp jquery實(shí)現(xiàn)圖片上傳和預(yù)覽效果
- PHP+JQuery+Ajax實(shí)現(xiàn)分頁(yè)方法詳解
- PHP+jQuery實(shí)現(xiàn)即點(diǎn)即改功能示例
相關(guān)文章
PHP實(shí)現(xiàn)合并兩個(gè)有序數(shù)組的方法分析
這篇文章主要介紹了PHP實(shí)現(xiàn)合并兩個(gè)有序數(shù)組的方法,結(jié)合實(shí)例形式分析了php針對(duì)數(shù)組的合并、遍歷、排序、去重等常見操作技巧,需要的朋友可以參考下2017-12-12
php開發(fā)分頁(yè)實(shí)現(xiàn)代碼
php開發(fā)分頁(yè)實(shí)現(xiàn)代碼,學(xué)習(xí)php的朋友可以參考下2012-04-04
PHP基于openssl實(shí)現(xiàn)的非對(duì)稱加密操作示例
這篇文章主要介紹了PHP基于openssl實(shí)現(xiàn)的非對(duì)稱加密操作,結(jié)合實(shí)例形式分析了openssl安裝、密鑰生成及php基于openssl的非對(duì)稱加密算法相關(guān)操作技巧,需要的朋友可以參考下2019-01-01
CodeIgniter php mvc框架 中國(guó)網(wǎng)站
CodeIgniter 是一個(gè)小巧但功能強(qiáng)大的 PHP 框架,作為一個(gè)簡(jiǎn)單而“優(yōu)雅”的工具包,它可以為 PHP 程序員建立功能完善的 Web 應(yīng)用程序。如果你是一個(gè)使用共享主機(jī),并且為客戶所要求的期限而煩惱的開發(fā)人員,如果你已經(jīng)厭倦了那些傻大笨粗的框架2008-05-05

