數(shù)據(jù)加載中……
          JS分頁,存下,免得再去項目找
          JS分頁函數(shù):
           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+"&nbsp;<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+"&nbsp;<a href='"+config.url+"?"+pfx+"startIndex="+startIndex+param+"' >"+template.previousPageLabel+"</a>";//上一頁
          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+"&nbsp;<strong>["+(thisPage+i+1)+"]</strong>";
          30                     }else{
          31                         navStr=navStr+"&nbsp;<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+"&nbsp;<a href='"+config.url+"?"+pfx+"startIndex="+startIndex+param+"' >"+template.nextPageLabel+"</a>";//下一頁
          38             startIndex=(totalPage-1)*config.pageSize;
          39             navStr=navStr+"&nbsp;<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         }

          頁面調(diào)用方法:
          $(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"],   //在ID為pags,pagsTop的div里顯示導(dǎo)航
                          template:{firstPageLabel:
          "首頁",previousPageLabel:"上一頁",nextPageLabel:"Next",lastPageLabel:"Last"},
                          param:
          "form.cid=<s:property value='form.cid' default='0' />"
                      };
                      pageNavBar(myconfig);
                  });

          服務(wù)端,因為我用的是mysql,所以只要有startIndex,pagesize就可以分頁了,當(dāng)然還要傳個totalRecords回來,可以提供給JS使用.

          posted on 2009-02-06 11:36 菜板 閱讀(208) 評論(0)  編輯  收藏 所屬分類: orther


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 浠水县| 禄丰县| 鄂托克前旗| 陵水| 萝北县| 乐至县| 吉木萨尔县| 扬州市| 南召县| 银川市| 井陉县| 东山县| 济源市| 瑞昌市| 怀宁县| 宁都县| 江阴市| 长泰县| 杨浦区| 克山县| 淮安市| 南溪县| 溆浦县| 呼玛县| 宁夏| 五寨县| 昆明市| 唐河县| 柞水县| 邹城市| 陈巴尔虎旗| 嵩明县| 秀山| 牡丹江市| 和静县| 泗洪县| 大庆市| 卢氏县| 清丰县| 红河县| 景谷|