js分页(把公司同事的贴过来了,嘿嘿)
//使用说明:需要在页面中做如下配置
//1. 为结果表的<tr>标签增加class:'row'
//2. 配置空的<span id="xxx"></span>标签,id分别为currentPage和pageCount来展示当前页数和总页数
//3. 全局变量pageSize控制每页容量,该变量发生变化后调用refreshPageSplit()可实现刷新
//使用时在页面加载完毕后为pageSize赋值,然后调用一次initPageSplit()
//之后可通过firstPage(), lastPage(), previousPage(), nextPage()实现翻页
var rowCount = null; //总条目数
var pageCount = null; //总页数
var currentPage = null; //当前页
var pageSize = null; //每页容量
function initPageSplit(){
if (pageSize==null) pageSize = 5;
rowCount = $(".row").length;
pageCount = Math.ceil(rowCount/pageSize);
currentPage = 1;
refreshPageSplit();
}
function refreshPageSplit() {
if (pageSize==null) pageSize = 5;
pageCount = Math.ceil(rowCount/pageSize);
if (currentPage > pageCount) currentPage = pageCount;
$("#currentPage").html(currentPage);
$("#pageCount").html(pageCount);
$.grep($(".row"), function (ele, index){
if (index>=(currentPage-1)*pageSize && index<currentPage*pageSize)
$(ele).show();
else
$(ele).hide();
});
}
function firstPage(){
currentPage = 1;
refreshPageSplit();
}
function lastPage(){
currentPage = pageCount;
refreshPageSplit();
}
function previousPage(){
if (currentPage>1){
currentPage--;
refreshPageSplit();
}
}
function nextPage(){
if (currentPage<pageCount){
currentPage++;
refreshPageSplit();
}
}