注意:本地分页适用于数据量小的地方,如果数据量大,不建议使用本地分页
代码语言:javascript复制var iTable = document.getElementById("iTable");
var rows = iTable.rows.length;
var pageSize = 3;//每页显示条数
var pageNum = 0;//总页数
var current = 1;
if(rows/pageSize > parseInt(rows/pageSize)){
pageNum = parseInt(rows/pageSize) 1;
}else{
pageNum = rows/pageSize;
}
function toPage(current){
var startRow = (current-1)*pageSize 1;
var endRow = current*pageSize;
for(var i=1;i<(rows 1);i ){
var iRow = iTable.rows[i-1];
if(i>=startRow && i<=endRow){
iRow.style.display="table-row";
}else{
iRow.style.display="none";
}
}
var pageHtml = "<li>当前" current "页/共" pageNum "页</li>";
if(current == 1){
pageHtml = pageHtml "<li class='disabled'>首页</li>";
pageHtml = pageHtml "<li class='disabled'>上一页</li>";
}else{
pageHtml = pageHtml "<li><a onClick='toPage(1)'>首页</a></li>";
pageHtml = pageHtml "<li><a onClick='toPage(" (current-1) ")'>上一页</a></li>";
}
if(current == pageNum){
pageHtml = pageHtml "<li class='disabled'>下一页</li>";
pageHtml = pageHtml "<li class='disabled'>尾页</li>";
}else{
pageHtml = pageHtml "<li><a onClick='toPage(" (current 1) ")'>下一页</a></li>";
pageHtml = pageHtml "<li><a onClick='toPage(" pageNum ")'>尾页</a></li>";
}
document.getElementById("pagination").innerHTML=pageHtml;
}
toPage(1);