關於CI架構實現ajax分頁和全選,反選,不選以及大量刪除的代碼

來源:互聯網
上載者:User
CodeIgniter 是一個小巧但功能強大的 PHP 架構。這篇文章主要介紹了CI架構(ajax分頁,全選,反選,不選,大量刪除)完整代碼,需要的朋友可以參考下

CodeIgniter 是一個小巧但功能強大的 PHP 架構,作為一個簡單而“優雅”的工具包,它可以為開發人員們建立功能完善的 Web 應用程式。是比較主流的一個PHP架構。

下面給大家介紹CI架構(ajax分頁,全選,反選,不選,大量刪除)完整代碼,具體代碼如下所示:

//ajax分頁+搜尋(視圖層)function ajax_page(page){var sou = $('#sou').val();$.ajax({type: "POST",dataType: "json",url: "<?PHP echo site_url('Welcome/ajax_page')?>",data: "page="+page+"&sou="+sou,success: function(data){var str="";str+="<table border='1' style='text-align:center'>";str+="<tr>";str+="<td><input type='checkbox' class='quan'/></td>";str+="<td>ID</td>";str+="<td>使用者名稱</td>";str+="<td>操作</td>";str+="</tr>";$.each(data.list,function(i,item){if(item.state==0){var locks = "<a href='JavaScript:void(0)' class='lok' fla='"+item.id+"' id='lock"+item.id+"'>未鎖定</a>"}else{var locks = "<a href='javascript:void(0)' class='lok' fla='"+item.id+"' id='lock"+item.id+"'>鎖定</a>"}str+="<tr id='av"+item.id+"'>";str+="<td><input type='checkbox' class='ss' value='"+item.id+"'/></td>";str+="<td>"+item.id+"</td>";str+="<td>"+item.name+"</td>";str+="<td>"+locks+"</td>";str+="</tr>";})str+="<tr>";str+="<td><input type='button' id='pdel' value='大量刪除'></td>"str+="</tr>";str+="</table>";str+=data.pagestr;$('#content').html(str);}})}//狀態切換$(document).on('click','.lok',function(){var id = $(this).attr('fla');$.ajax({type: "POST",url: "<?php echo site_url('Welcome/upds')?>",data: "id="+id,success: function(msg){if(msg==1){$('#lock'+id).html("鎖定");}else{$('#lock'+id).html("未鎖定");}}})})//大量刪除$(document).on('click','#pdel',function(){var ids = $('.ss');var str="";$.each(ids,function(i,item){if(ids[i].checked==true){str=str+','+ids[i].value;}})var new_str=str.substr(1);$.ajax({type: "POST",url: "<?php echo site_url('Welcome/pdels')?>",data: "new_str="+new_str,success: function(msg){$.each(ids,function(i,item){if(ids[i].checked==true){$('#av'+ids[i].value).remove();}})}})})//全選(複選框)$(document).on('click','.quan',function(){var obj = $(':checkbox');var ids = $('.ss');if(obj[0].checked==true){$.each(ids,function(i,item){ids[i].checked=true;})}else{$.each(ids,function(i,item){ids[i].checked=false;})}})<td><input type="checkbox" class="checks" value="<?php echo $val['u_id']?>"/></td>//全選(按鈕)$('.quan').click(function(){var ids = $('input:checkbox');$.each(ids,function(i,item){ids[i].checked=true;})})//全不選$('.bu').click(function(){var ids = $('input:checkbox');$.each(ids,function(i,item){ids[i].checked=false;})})//反選$('.fan').click(function(){var ids = $('.checks');$.each(ids,function(i,item){ids[i].checked=!ids[i].checked;})})//即點即改$(document).on('click','.ss',function(){var id = $(this).attr('id');var con = $(this).text();$(this).parent().html("<input type='text' id='"+id+"' class='aa' value='"+con+"'>");$('.aa').val('').focus().val(con);$(document).on('blur','.aa',function(){var id = $(this).attr('id');var cons = $(this).val();$(this).parent().html("<span id='"+id+"' class='ss'>"+cons+"</span>");$.ajax({type: "POST",url: "<?php echo site_url('Welcome/upd_ji')?>",data: "id="+id+"&cons="+cons})})})//匯出$(document).on('click','#chu',function(){var sou = $('#sou').val();location.href="<?php echo site_url('excel/export')?>?sou="+sou;})//ajax分頁(控制層)public function ajax_page(){$sou = $this->input->post('sou');$count = $this->db->where("name like '%$sou%'")->count_all_results("peng");$number = 3;$this->session->set_userdata('number',$number);$pagecount = ceil($count/$number);@$page = $_POST['page']?$_POST['page']:1;$this->session->set_userdata('page',$page);$start = ($page-1)*$number;$arr['list'] = $this->db->where("name like '%$sou%'")->limit($number,$start)->get("peng")->result_array();$up_page = $page-1<1?1:$page-1;$down_page = $page+1>$pagecount?$pagecount:$page+1;$str = "";$str .= "<a href='javascript:void(0)' onclick='ajax_page($up_page)'>上一頁</a>";for($i=1;$i<=$pagecount;$i++){if($i==$page){$str .= "--"."<b>$i</b>";}else{$str .= "--"."<a href='javascript:void(0)' onclick='ajax_page($i)'>$i</a>";}}$str .= "--"."<a href='javascript:void(0)' onclick='ajax_page($down_page)'>下一頁</a>";$arr['pagestr'] = $str;echo json_encode($arr);}//狀態切換public function upds(){$id = $this->input->post('id');$arr = $this->db->get_where("peng","id='$id'")->row_array();if($arr['state']==0){$data['state']=1;$this->db->where("id='$id'")->update("peng",$data);echo "1";}else{$data['state']=0;$this->db->where("id='$id'")->update("peng",$data);echo "2";}}//大量刪除public function pdels(){$str = $this->input->post('new_str');$this->db->where("id in($str)")->delete("peng");}

以上就是本文的全部內容,希望對大家的學習有所協助,更多相關內容請關注topic.alibabacloud.com!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.