首先上效果图:
以下为封装好的 方法:
function Paging(pageNum,pageSize,totalCount,skipCount,fuctionName,currentStyleName,currentUseLink,preText,nextText,firstText,lastText){
var returnValue = "";
var begin = 1;
var end = 1;
var totalpage = Math.floor(totalCount / pageSize);
if(totalCount % pageSize >0){
totalpage ++;
}
if(preText == null){
firstText = "prev";
}
if(nextText == null){
nextText = "next";
}
begin = pageNum - skipCount;
end = pageNum + skipCount;
if(begin <= 0){
end = end - begin +1;
begin = 1;
}
if(end > totalpage){
end = totalpage;
}
for(count = begin;count <= end;count ++){
if(currentUseLink){
if(count == pageNum){
returnValue += "<a class=\""+currentStyleName+"\" href=\"javascript:void(0);\" οnclick=\""+fuctionName+"("+count.toString()+");\">"+count.toString()+"</a> ";
}
else{
returnValue += "<a href=\"javascript:void(0);\" οnclick=\"" + fuctionName + "(" + count.toString() + ");\">" + count.toString() + "</a> ";
}
}
else {
if (count == pageNum) {
returnValue += "<span class=\""+currentStyleName+"\">"+count.toString()+"</span> ";
}
else{
returnValue += "<a href=\"javascript:void(0);\" οnclick=\""+fuctionName+"("+count.toString()+");\">"+count.toString()+"</a> ";}
}
}
if(pageNum - skipCount >1){
returnValue = " ... "+returnValue;
}
if(pageNum + skipCount < totalpage){
returnValue = returnValue + " ... ";
}
if(pageNum > 1){
returnValue = "<a href=\"javascript:void(0);\" οnclick=\""+fuctionName+"("+(pageNum - 1).toString()+");\"> " + preText + "</a> " + returnValue;
}
if(pageNum < totalpage){
returnValue = returnValue + " <a href=\"javascript:void(0);\" οnclick=\""+fuctionName+"("+(pageNum+1).toString()+");\">" + nextText + "</a>";
}
if(firstText!= null){
if(pageNum >1){
returnValue = "<a href=\"javascript:void(0);\" οnclick=\""+fuctionName+"(1);\">" + firstText + "</a> " + returnValue;}
}
if(lastText !=null){
if(pageNum < totalpage){
returnValue = returnValue + " " + " <a href=\"javascript:void(0);\" οnclick=\""+fuctionName+"("+totalpage.toString()+");\">" + lastText + "</a>";}
}
return returnValue;
}