1 //pageSize蹇呴渶,totalRecords:蹇呴渶,startIndex蹇呴渶,contenter蹇呴渶
2 function pageNavBar(config){
3 //alert("pagesize:"+config.pageSize+" total:"+config.totalRecords+" unknowsss:"+config.startIndex);
4 var lastPage=0;
5 var startIndex=0;
6 var thisPage=1;
7 var template={firstPageLabel:"<<",previousPageLabel:"<",nextPageLabel:">",lastPageLabel:">>"};
8 var pfx=typeof(config.pfx)!="undefined"?config.pfx:"";
9 var param=typeof(config.param)!="undefined"?"&"+config.param:"";
10
11 if(typeof(config.template)!="undefined"){
12 template=config.template;
13 }
14 var totalPage=parseInt((config.totalRecords-1)/config.pageSize)+1;
15 totalPage=totalPage<1?1:totalPage;
16
17 var navStr="";
18
19 navStr=navStr+" <a href='"+config.url+"?"+pfx+"startIndex=0"+param+"' >"+template.firstPageLabel+"</a>"; //棣栭〉
20 startIndex=(config.startIndex-config.pageSize)<=0?0:(config.startIndex-config.pageSize);
21 navStr=navStr+" <a href='"+config.url+"?"+pfx+"startIndex="+startIndex+param+"' >"+template.previousPageLabel+"</a>";//涓婁竴欏?/span>
22
23 thisPage=parseInt(config.startIndex/15)+1;
24
25 for(var i=-5;i<6;i++){
26 if((thisPage+i)>=0 && (thisPage+i)<totalPage){
27 startIndex=(thisPage+i)*config.pageSize;
28 if(startIndex==config.startIndex){
29 navStr=navStr+" <strong>["+(thisPage+i+1)+"]</strong>";
30 }else{
31 navStr=navStr+" <a href='"+config.url+"?"+pfx+"startIndex="+startIndex+param+"' >"+(thisPage+i+1)+"</a>";
32 }
33 }
34 }
35
36 startIndex=(config.startIndex+config.pageSize)>=config.totalRecords?(totalPage-1)*config.pageSize:config.startIndex+config.pageSize;
37 navStr=navStr+" <a href='"+config.url+"?"+pfx+"startIndex="+startIndex+param+"' >"+template.nextPageLabel+"</a>";//涓嬩竴欏?/span>
38 startIndex=(totalPage-1)*config.pageSize;
39 navStr=navStr+" <a href='"+config.url+"?"+pfx+"startIndex="+startIndex+param+"' >"+template.lastPageLabel+"</a>";//鏈〉
40 if(config.contenter.constructor==Array){
41 $(config.contenter).each(function(){
42 $("#"+this).html(navStr);
43 });
44 }else{
45 $("#"+config.contenter).html(navStr);
46 }
47 }
欏甸潰璋冪敤鏂規(guī)硶:
$(document).ready(function(){
var myconfig={
pageSize:<s:property value="pages.pageSize" default="1"/>,
totalRecords:<s:property value="pages.totalRecords" default="0"/>,
startIndex:<s:property value="pages.startIndex" default="0"/>,
url:"${contextPath}/p/phone!list.act",
pfx:"pages.",
contenter:["pags","pagsTop"], //鍦↖D涓簆ags,pagsTop鐨刣iv閲屾樉紺哄鑸?br />
template:{firstPageLabel:"棣栭〉",previousPageLabel:"涓婁竴欏?/span>",nextPageLabel:"Next",lastPageLabel:"Last"},
param:"form.cid=<s:property value='form.cid' default='0' />"
};
pageNavBar(myconfig);
});
鏈嶅姟绔?鍥犱負(fù)鎴戠敤鐨勬槸mysql,鎵浠ュ彧瑕佹湁startIndex,pagesize灝卞彲浠ュ垎欏典簡,褰撶劧榪樿浼犱釜totalRecords鍥炴潵,鍙互鎻愪緵緇橨S浣跨敤.

]]>