《PHP編程:php+ajax簡(jiǎn)單實(shí)現(xiàn)全選刪除的方法》要點(diǎn):
本文介紹了PHP編程:php+ajax簡(jiǎn)單實(shí)現(xiàn)全選刪除的方法,希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
PHP編程本文實(shí)例講述了php+ajax簡(jiǎn)單實(shí)現(xiàn)全選刪除的方法.分享給大家供大家參考,具體如下:
PHP編程
<input type="checkbox" id="ckb_selectAll" onclick="selectAll()" title="選中/取消選中">
<a href="void(0);" onclick="del_()" title="刪除選定數(shù)據(jù)" style="font-weight:normal">刪除</a>
PHP編程↑全選checkbox
PHP編程
<input type="checkbox" class="ckb" id="+con.id+" value="+con.id+">
PHP編程↑為刪除項(xiàng),同一命名class為ckb,方便操作,同時(shí)將id值巧妙的放入input中,方便獲取.
PHP編程
function selectAll() {
if ($('#ckb_selectAll').is(':checked')) {
$(".ckb").attr("checked", true); //全部選中
} else {
$(".ckb").attr("checked", false);//全部取消
}
}
PHP編程↑選中事件
PHP編程
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("確定刪除?刪除后將無(wú)法恢復(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);
}
});
}
}
}
PHP編程↑刪除用ajax來(lái)處理.
PHP編程↓后臺(tái)操作數(shù)據(jù)庫(kù),處理刪除動(dòng)作.
PHP編程
$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;
PHP編程完成
PHP編程更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《PHP+ajax技巧與應(yīng)用小結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》
PHP編程希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助.
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/2490.html