<%@ page language="java" contentType="text/html charset=utf-8"
pageEncoding="utf-8"%>
<%
String path = request.getContextPath()
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath %>" />
<meta http-equiv="Content-Type"
content="text/html charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="scripts/jquery-1.5.1.js"></script>
<script type="text/javascript">
var list // the list of data
var totalPages // the total of pages
var pageSize = 5 // each size of page
var pageIndex = 1 // the index of current page
$(function(){
send()
})
function send() {
$.ajax({
url: "DistrictServlet",
type: "POST",
data: {"function":"list"},
dataType: "json",
success: function(data) {
// list = data
var records = data.length
if (records % pageSize == 0) {
totalPages = records / pageSize
} else {
totalPages = Math.round(records / pageSize)
}
$("#pageIndex").html(pageIndex)
$("#totalPages").html(totalPages)
binding(data)
}
})
}
function changePage() {
$.ajax({
url: "DistrictServlet",
type: "post",
data: {"function":"list"},
dataType: "json",
success: function(data) {
binding(data)
}
})
}
function binding(data) {
var start = (pageIndex - 1) * pageSize
var end = pageIndex * pageSize
var html = ""
$.each(data, function(index, district) {
if (index >= start && index < end) {
// show data
html += "<tr><td>" + district["id"]+ "</td><td>" +district["name"]+"</td></tr>" // .........
}
})
$("table").html(html)
$("#pageIndex").html(pageIndex)
}
function nextPage() {
pageIndex += 1
if (pageIndex > totalPages) {
pageIndex = totalPages
return
}
changePage()
}
function lastPage() {
pageIndex -= 1
if (pageIndex < 1) {
pageIndex = 1
return
}
changePage()
}
function skipPage(index) {
pageIndex = index
changePage()
}
</script>
</head>
<body>
<div><span id="pageIndex"></span>/<span id="totalPages"></span></div>
<div>
<a href="javascript: lastPage()">last</a>
<a href="javascript: nextPage()">next</a>
</div>
<div id="list"><table></table></div>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)