您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)thinkphp+jquery如何實(shí)現(xiàn)ajax多選反選不選刪除數(shù)據(jù)功能,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
代碼如下
《————HTML————》
//thinkphp循環(huán)顯示把data里fid賦予多選框 <volist name="data" id="vo"> <tr> <td><input type="checkbox" value="{$vo.fid}"/></td>//可在后面加td輸入?yún)?shù) </tr> </volist> <tr> <th width="80"><input type="checkbox" id="all"/>全選</th> <th width="80"><input type="button" value="全選" class="btn" id="selectAll" /></th> <th width="80"><input type="button" value="全不選" class="btn" id="unSelect" /></th> <th><input type="button" value="反選" class="btn" id="reverse" /></th> <th width="180"> <a href="javascript:void(0);" rel="external nofollow" onclick="del()" title="刪除選定數(shù)據(jù)">刪除</a> </th> </tr>
《————jsvascript————》
<script> //多選 $("#all").click(function(){ if(this.checked){ $("#list :checkbox").attr("checked", true); }else{ $("#list :checkbox").attr("checked", false); } }); //當(dāng)點(diǎn)到全選按鈕 $("#selectAll").click(function () { $("#list :checkbox,#all").attr("checked", true); }); //全不選 $("#unSelect").click(function () { $("#list :checkbox,#all").attr("checked", false); }); //反選 $("#reverse").click(function () { $("#list :checkbox").each(function () { $(this).attr("checked", !$(this).attr("checked")); }); allCheck(); }); //刪除 function del(){ var valArr = new Array; $("#list :checkbox[checked]").each(function(i){ valArr[i] = $(this).val(); }); var vals = valArr.join(',');//數(shù)組轉(zhuǎn)換以逗號(hào)隔開的字符串 if (valArr.length == 0) { alert('請(qǐng)選擇要?jiǎng)h除的選項(xiàng)'); }else{ if (confirm("確定刪除?刪除后將無(wú)法恢復(fù)。")){ var data={name:vals}; $.ajax({ type: "post", url: "{:U('College/School/faculty_del')}",//url為tp方法(控制器/方法) data:data, success: function(json) { var obj = eval('(' + json + ')');//返回回來(lái)的json轉(zhuǎn)化為js對(duì)象 if (parseInt(obj.counts) > 0) { alert(obj.des); location.reload(); } else { alert(obj.des); } }, error: function(XMLHttpRequest, textStatus) { alert("頁(yè)面請(qǐng)求錯(cuò)誤,請(qǐng)檢查重試或聯(lián)系管理員!\n" + textStatus); } }); } } } </script>
《————PHP————》
public function faculty_del(){ $fid = trim($_POST['name']); //以下為查詢條件 $bname['deletemark'] = 0; $res = $this->faculty_model ->where(array('fid'=>array('in',$fid))) ->save($bname); //查詢條件為你的查詢條件,我這邊為邏輯刪除,修改字段值就好 // echo $this->faculty_model->getLastSql(); // var_dump($res); // exit; if ($res) { $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; exit; }
由于是異步所以你發(fā)過來(lái)的數(shù)據(jù)都在控制臺(tái)查看,當(dāng)前頁(yè)面沒輸出,不要去頁(yè)面上去找。
關(guān)于“thinkphp+jquery如何實(shí)現(xiàn)ajax多選反選不選刪除數(shù)據(jù)功能”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。