首页 > 作文

thinkphp5ajax分頁&&搜索後分頁

更新时间:2023-04-07 06:48:45 阅读: 评论:0

//控制器層

//分頁
public function list_january_table(){

//設置當前頁
$page = input(“post.page”) ? input(“post.page”) : 1;
//設置每頁顯示條數
$size = 3;
//查詢總條數
$num = db::table(“january_table”)->count();
//查詢總頁數
$end = ceil($num/$size);
//計算偏移量
$offt = ($page-1)*$size;
//查詢所有條數
$data = db::table(“january_table”)->limit($offt,$size)->lect();
//手機號碼中獎四位隱藏
foreach ($data as $key=>$val){
$data[$key][‘mobile’]=substr($val[‘mobile’],0,3).’****’.substr($val[‘mobile’],7,4);
}
return view(“list_january_table”,[‘list’=>$data,’end’=>$end]);
}

//ajax分頁&搜索后分頁
public function ajax_page_january_table(){
$arch = input(“post.arch”);
if ($arch==””){
//設置當前頁
$page = input(“post.page”) ? input(“post.page”) : 1;
//設置每頁顯示條數
$size = 3;
//查詢總條數
$num = db::table(“january_table”)->count();
//查詢總頁數
$end = ceil($num/$size);
//計算偏移量
$offt = ($page-1)*$size;
//查詢所有條數
$data = db::table(“january_table”)->limit($offt,$size)->lect();
}el{
//設置當前頁
$page = input(“post.page”) ? input(“post.page”) : 1;
//設置每頁顯示條數
$size = 3;
//查詢總條數
$num = db::table(“january_table”)->where(‘urname’,’like’,”%$arch%”)->count();
//查詢總頁數
$end = ceil($num/$size);
//計算偏移量
$offt = ($page-1)*$size;
//查詢所有條數
$data = db::table(“january_table”)->where(‘urname’,’like’,”%$arch%”)->limit($offt,$size)->lect();
}
return json($data);
}

//視圖層

<!doctype html>
<html lang=”en”>
<head>
<meta chart=”utf-8″>
<title>展示頁面</title>
</head>
<body>
<center>
<h1>马克思;展示頁面</h1>
<input type=”text” name=”arch” id=”arch”><input type=”button” class=”page” value=”搜索”>
<table border=”1″>
<tr>
<td>選擇</td>
<td>班名</td>
<td>年齡</td>
<td>性別</td>
<td>簡介</td>
<td>手機</td>
<td>頭像</td>
<td>詳情</td>
<td>操作</td>
</tr>
<tbody id=”tb”>
{volist name=”list” id=”vo”}
<tr id=”{$vo.id}”>
<td><input type=”checkbox” name=”check” value=”{$vo.id}”>{$vo.id}</td>
<td fd=”urname” class=”cli_up”>{$vo.urname}</td>
<td>{$vo.age}</td>
<td ida=”{$vo.id}” class=”up_time”>
{if condition=”$vo.x neq ‘1’”}男
{el /} 女
{/if}
</td>
<td>{$vo.desc}</td>
<td>{$vo.mobile}</td>
<td><img src=”__static__/uploads/{$vo.photo}” width=”80px” alt=””></td>
<td>{$vo.content}</td>
<td><a href=”javascript:void (0)” class=”del” id_del=”{$vo.id}”>刪除</a></td>
</tr>
{/volist}
</tbody>
<java程序员面试题/table>
<a href=”{:url(‘index/add_january_table’)}”>添加</a>
<input type=”button” class=”yes” val新年祝语ue=”全選”>
<input type=”button” class=”no” value=”全不選”>
<input type=”button” class=”yn” value=”反選”>
<input type=”button” class=”del_all” value=”批量刪除”>
<input type=”hidden” name=”a_page” id=”a_page” value=”1″>
<input type=”hidden” name=”last_page” id=”last_page” value=”{$end}”>
<a href=”javascript:void (0)” class=”page”>首頁</a>
<a href=”javascript:void (0)” class=”page”>上一頁</a>
<a href=”javascript:void (0)” class=”page”>下一頁</a>
<a href=”javascript:void (0)” class=”page”>尾頁</a>
</center>
<script src=”__static__/jquery-3.3.1.min.js”></script>
<script>
//刪除
$(document).on(“click”,”.del”,function () {
var id = $(this).attr(“id_del”);
$.ajax({
url:”{:url(‘index/del_january_table’)}”,
type:”get”,
datatype:”json”,
data:{
id:id,
},
success:function (data) {
if (data==1){
history.go(0);
} el {
alert(“刪除失敗”)
}
}
})
})
//批量刪除
$(document).on(“click”,”.del_all”,function () {
var check = document.getelementsbyname(“check”);
var str= “”;
for (i=0;i<check.length;i++) {
if (check[i].checked == true) {
str += “,” + check[i].value;
}
}
var id = str.substr(1);alert(id)
$.ajax({
url:”{:url(‘index/del_january_table’)}”,
type:”get”,
datatype:”json”,
data:{
id:id,
},
success:function (data) {
if (data==1){
alert(“刪除成功”);
history.go(0);
} el {
alert(“刪除失敗”)
}
}
});
})
//全選
$(document).on(“click”,”.yes”,function () {
var check = document.getelementsbyname(“check”);
for (i=0;i<check.length;i++){
if (check[i].checked==fal){
check[i].checked = true;
}
}
})
//全不選
$(document).on(“click”,”.no”,function () {
var check = document.getelementsbyname(“check”);
for (i=0;i<check.length;i++){
if (check[i].checked==true){
check[i].checked = fal;
}
}
})
//反選
$(document).on(“click”,”.yn”,function () {
var check = document.getelementsbyname(“check”);
for (i=0;i<check.length;i++){
if (check[i].checked==true){
check[i].checked = fal;
}el {
check[i].checked = true;
}
}
})
//即時更改
$(document).on(“click”,”.up_time”,function () {
var id = $(this).attr(“ida”);
var x = $(this).text();
var obj = $(this);
$.ajax({
url:”{:url(‘index/up_time_january_table’)}”,
type:”post”,
datatype:”json”,
data:{
id:id,
x:x,
},
success:function (data) {
if (data.code==1){
obj.html(data.message);
}el {
obj.html(data.message);
}
}
});
})
//即點即改
$(document).ready(function () {
$(“.cli_up”).dblclick(function () {
var id = $(this).parent().attr(“id”);
var fd = $(this).attr(“fd”);
var text = $(this).text();
var td = $(this);
$(this).html(‘<input type=”text” class=R丙肝炎的早期症状21;cli’+id+fd+'” value=”‘+text+'”>’);
$(“.cli”+id+fd).blur(function () {
var new_val = $(this).val();
$.ajax({
url:”{:url(‘index/update_january_table’)}”,
type:”post”,
datatype:”json”,
data:{
id:id,
fd:fd,
new_val:new_val,
},
success:function (data) {
console.log(data);
if (data==1){
td.text(new_val);
} el {
td.text(text);
}
}
})
})
})
})
//ajax分頁&搜索
$(document).on(“click”,”.page”,function () {
var arch = $(“#arch”).val();
var a_val = $(this).text();
var a_page = $(“#a_page”).val();
va我是一棵小小草r last_page = $(“#last_page”).val();
if (a_val==”首頁”){
var page = 1;
} el if (a_val==”上一頁”){
var page = parint(a_page)-1 < 1 ? 1 : parint(a_page)-1;
} el if (a_val==”下一頁”){
var page = parint(a_page)+1 > last_page ? last_page : parint(a_page)+1;
} el if (a_val==”尾頁”){
var page = last_page;
}
$.ajax({
url:”{:url(‘index/ajax_page_january_table’)}”,
type:”post”,
datatype:”json”,
data:{
page:page,
arch:arch,
},
success:function (data) {
var str = “”;
$.each(data,function (key,val) {
str+='<tr>\n’ +
‘ <td><input type=”checkbox” name=”check”>’+val.id+'</td>\n’ +
‘ <td>’+val.urname+'</td>\n’ +
‘ <td>’+val.age+'</td>\n’ +
‘ <td ida=”‘+val.id+'” class=”up_time”>’+val.x+'</td>\n’ +
‘ <td>’+val.desc+'</td>\n’ +
‘ <td>’+val.mobile+'</td>\n’ +
‘ <td><img src=”__static__/uploads/’+val.photo+'” width=”80px” alt=””></td>\n’ +
‘ <td>’+val.content+'</td>\n’ +
‘ <td><a href=”javascript:void (0)”>刪除</a></td>\n’ +
‘ </tr>’;
})
$(“#tb”).html(str);
$(“#a_page”).val(page);
}
})
})
</script>
</body>
</html>

本文发布于:2023-04-07 06:48:43,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/b4c2bd4ddaf019aab26b50fad59d3ce4.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:thinkphp5ajax分頁&&搜索後分頁.doc

本文 PDF 下载地址:thinkphp5ajax分頁&&搜索後分頁.pdf

标签:上一   下一   偏移量   批量
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图