CodeIgniter 是一个小巧但功能强大的 PHP 框架,作为一个简单而“优雅”的工具包,它可以为开发者们建立功能完善的 Web 应用程序。是比较主流的一个PHP框架。
下面给大家介绍CI框架(ajax分页,全选,反选,不选,批量删除)完整代码,具体代码如下所示:
PHP;">
//ajax分页+搜索(视图层)
function ajax_page(page){
var sou = $('#sou').val();
$.ajax({
type: "POST",dataType: "json",url: "",data: "page="+page+"&sou="+sou,success: function(data){
var str="";
str+="";
str+="
",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,item){ if(ids[i].checked==true){ str=str+','+ids[i].value; } }) var new_str=str.substr(1); $.ajax({ type: "POST",url: "",data: "new_str="+new_str,success: function(msg){ $.each(ids,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,item){ ids[i].checked=true; }) }else{ $.each(ids,item){ ids[i].checked=false; }) } }) | Box" class="checks" value=""/> | Box'); $.each(ids,item){ ids[i].checked=true; }) }) //全不选 $('.bu').click(function(){ var ids = $('input:checkBox'); $.each(ids,item){ ids[i].checked=false; }) }) //反选 $('.fan').click(function(){ var ids = $('.checks'); $.each(ids,item){ ids[i].checked=!ids[i].checked; }) }) //即点即改 $(document).on('click','.ss',function(){ var id = $(this).attr('id'); var con = $(this).text(); $(this).parent().html(""); $('.aa').val('').focus().val(con); $(document).on('blur','.aa',function(){ var id = $(this).attr('id'); var cons = $(this).val(); $(this).parent().html(""+cons+""); $.ajax({ type: "POST",url: "",data: "id="+id+"&cons="+cons }) }) }) //导出 $(document).on('click','#chu',function(){ var sou = $('#sou').val(); location.href="?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 .= "上一页"; for($i=1;$i<=$pagecount;$i++){ if($i==$page){ $str .= "--"."$i"; }else{ $str .= "--"."$i"; } } $str .= "--"."下一页"; $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"); }