Location:Home >> News >> 开发

CI框架(ajax分页,全选,反选,不选,批量删除)完整代码详解

CI框架(ajax分页,全选,反选,不选,批量删除)完整代码详解

CodeIgniter 是一个小巧但功能强大的 PHP 框架,作为一个简单而“优雅”的工具包,它可以为开发者们建立功能完善的 Web 应用程序。是比较主流的一个PHP框架。

下面给大家介绍CI框架(ajax分页,全选,反选,不选,批量删除)完整代码,具体代码如下所示:

?
//全选(按钮)
$('.quan').click(function(){
varids = $('input:checkbox');
$.each(ids,function(i,item){
ids[i].checked=true;
})
})
//全不选
$('.bu').click(function(){
varids = $('input:checkbox');
$.each(ids,function(i,item){
ids[i].checked=false;
})
})
//反选
$('.fan').click(function(){
varids = $('.checks');
$.each(ids,function(i,item){
ids[i].checked=!ids[i].checked;
})
})
//即点即改
$(document).on('click','.ss',function(){
varid = $(this).attr('id');
varcon = $(this).text();
$(this).parent().html("<input type='text' id='"+id+"' class='aa' value='"+con+"'>");
$('.aa').val('').focus().val(con);
$(document).on('blur','.aa',function(){
varid = $(this).attr('id');
varcons = $(this).val();
$(this).parent().html(""+cons+"");
$.ajax({
type:"POST",
url:"<?php echo site_url('Welcome/upd_ji')?>",
data:"id="+id+"&cons="+cons
})
})
})
//导出
$(document).on('click','#chu',function(){
varsou = $('#sou').val();
location.href="<?php echo site_url('excel/export')?>?sou="+sou;
})
//ajax分页(控制层)
publicfunctionajax_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>
$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;
echojson_encode($arr);
}
//状态切换
publicfunctionupds(){
$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";
}
}
//批量删除
publicfunctionpdels(){
$str=$this->input->post('new_str');
$this->db->where("id in($str)")->delete("peng");
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//ajax分页+搜索(视图层)
functionajax_page(page){
varsou = $('#sou').val();
$.ajax({
type:"POST",
dataType:"json",
url:"<?PHP echo site_url('Welcome/ajax_page')?>",
data:"page="+page+"&sou="+sou,
success:function(data){
varstr="";
str+="";
str+="
";
str+="
";
str+="
";
str+="
";
str+="
";
str+="
";
$.each(data.list,function(i,item){
if(item.state==0){
varlocks ="未锁定"
}else{
varlocks ="锁定"
}
str+="
";
str+="
";
str+="
";
str+="
";
str+="
";
str+="
";
})
str+="
";
str+="
"
str+="
";
str+="
<input type='checkbox' class='quan'/> ID 用户名 操作
<input type='checkbox' class='ss' value='"+item.id+"'/> "+item.id+" "+item.name+" "+locks+"
<input type='button' id='pdel' value='批量删除'>
";
str+=data.pagestr;
$('#content').html(str);
}
})
}
//状态切换
$(document).on('click','.lok',function(){
varid = $(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(){
varids = $('.ss');
varstr="";
$.each(ids,function(i,item){
if(ids[i].checked==true){
str=str+','+ids[i].value;
}
})
varnew_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(){
varobj = $(':checkbox');
varids = $('.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;
})
}
})
<input type="checkbox"class="checks"value="<?php echo $val['u_id']?>"/>

以上所述是小编给大家介绍的CI框架(ajax分页,全选,反选,不选,批量删除)完整代码详解,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

Special Reminder & Disclaimer:
The information of this website comes from the Internet. The content (pictures, videos and words) released by this website is mainly the content submitted by users and reproduced by users. The purpose is to convey more information, which does not mean that this website agrees with its views. The originality, statements, and content of this article have not been verified by this website. We do not guarantee or promise the authenticity, completeness, or timeliness of this article or all or part of its content or text. Please verify the relevant content on your own. This website does not assume direct or joint liability for infringement of such works. If any content on this website infringes on your rights, please contact us promptly (email: nssa@soufind.com )This site will complete the processing within 72 hours. The original content on this website cannot be reproduced without permission, or the source must be indicated when reprinting: nssa.vip Aerospace Alliance

Author: 本站网友

Recommended for you

Post comments

admin

Contact Us

Contact Us

Online consultation: QQ交谈

Email: service#soufind.com

follow us on WeChat
Scan and follow us on WeChat

Scan and follow us on WeChat