tp5框架中jquery+ajax分页

时间:2022-04-11 09:17:57

jaxa分页,点击按钮直接替换数据,

//php代码
$page=Request::instance()->param("page");
$page = empty($page)?:$page;
$count = Db::table('week3')->count();
$length = ;
$num_page = ceil($count/$length);
$limit = ($page-)*$length;
$data = Db::table('week3')->limit($limit,$length)->select();
$arr['data'] = $data;
$arr['home_page'] = ;
$arr['prev_page'] = $page-<=?:$page-;
$arr['next_page'] = $page+>=$num_page?$num_page:$page+;
$arr['last_page'] = $num_page;
return view('show',['list'=>$arr]);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>展示数据</title>
</head>
<body id="body">
<center>
<table border="">
<tr >
<td>ID</td>
<td>姓名</td>
<td>密码</td>
</tr>
{volist name="list.data" id="vo"}
<tr class="{$vo.id}">
<td>{$vo.id}</td>
<td>{$vo.name}</td>
<td>{$vo.password}</td>
</tr>
{/volist}
</table>
<input type="hidden" name="page" id="page" value="">
<a href="javascript:void(0);" onclick="page({$list.home_page})">首页</a>
<a href="javascript:void(0);" onclick="page({$list.prev_page})">上一页</a>
<a href="javascript:void(0);" onclick="page({$list.next_page})">下一页</a>
<a href="javascript:void(0);" onclick="page({$list.last_page})">尾页</a>
</center>
</body>
</html>
<script src="/static/js/jquery.js"></script>
<script>
function page(obj){
$.get("{:url('page/show')}?page="+obj,
function(data){
$("body").html(data);
}
);
}
</script>

相关文章