JS, Jquery进行前台翻页

这里我们是根据table来进行前台翻页,这里只有上下翻页,没有直接到第一页和到最后一页

function goPage(pno,psize){//pon就是从第几页开始,psize就是几条为一页
var itable = document.getElementById("myTab1");//此id就是table的id
var num = itable.rows.length-1;
var totalPage = 0;
var pageSize = psize;
if(num/pageSize > parseInt(num/pageSize)){
totalPage=parseInt(num/pageSize)+1;
}else{
totalPage=parseInt(num/pageSize);
}
var currentPage = pno;
var startRow = (currentPage - 1) * pageSize+1;
var endRow = currentPage * pageSize;
endRow = (endRow > num)? num : endRow;
for(var i=1;i<(num+1);i++){
var irow = itable.rows[i];
if(i>=startRow && i<=endRow){
irow.style.display = "block";
}else{
irow.style.display = "none";
}
}

var tempStr = "";
if(currentPage>1){
tempStr += "<a href="#" onClick="goPage("+(currentPage-1)+","+psize+")"><img src='/images/arrow_up.gif' border='0'></a>"
}
if(currentPage<totalPage){
tempStr += "<a href="#" onClick="goPage("+(currentPage+1)+","+psize+")"><img src='/images/arrow_down.gif' border='0'></a>";
}
document.getElementById("barcon").innerHTML = tempStr;//此id就是翻页的图标插入的地方
}

<table width="100%" style="padding-top: 10px;">
<tr>
<td><div id="barcon" name="barcon"></div></td>
</tr>
</table>

原文地址:https://www.cnblogs.com/echo777/p/6805814.html