js写分页

jsp:< input value ="1" id ="current" type ="hidden"/>

< div  id =  "fenYe" >
      </ div  >
js:
//四级下拉关系配合数据
 
$( function (){
            //进来就查询全部
          fenye(1);
          chuliYeMa();
     });
var  totalPage;
       //分页方法
     function  fenye(current){
                if (current ==  undefined ){
                   current = 1;
              }
                //将点击后的页放入隐藏框里
              $(  "#current"  ).val(current);
                //详细原因
              var  xxYuanyinSelLen = $( "#xxYuanyinSel option" ).length;
                var  xxYuanyinSelVal = $( "#xxYuanyinSel option:selected" ).val();
                //详细部位
              var  xxbuweiSelLen = $( "#xxbuweiSel option" ).length;
                var  xxbuweiSelVal = $( "#xxbuweiSel option:selected" ).val();
                //部位
              var  buweiClassSelLen = $( "#buweiClassSel option" ).length;
                var  buweiClassSelVal = $( "#buweiClassSel option:selected" ).val();
                //项目
              var  xiangMuClassSelLen = $( "#xiangMuClassSel option"  ).length;
                var  xiangMuClassSelVal = $( "#xiangMuClassSel option:selected"  ).val();
                //刷新表数据
              if  (xxYuanyinSelLen != 0 && xxYuanyinSelVal !=  "0"  ){
                     //按详细原因查询
                   var  className =  "xxyuanyin" ;
               fenyeGetMsg(className,xxYuanyinSelVal,current);
                 //查询时将总页数查出来
               getTotalPage(className,xxYuanyinSelVal);
              }  else if (xxbuweiSelLen != 0 && xxbuweiSelVal !=  "0"  ){
                     //按详细部位查询
                   var  className =  "xxbuwei" ;
               fenyeGetMsg(className,xxbuweiSelVal,current);
                 //查询时将总页数查出来
               getTotalPage(className,xxbuweiSelVal);
              }  else if (buweiClassSelLen != 0 && buweiClassSelVal !=  "0"  ){
                     //按部位查询
                   var  className =  "buweiClass" ;
                   fenyeGetMsg(className,buweiClassSelVal,current);
                 //查询时将总页数查出来
               getTotalPage(className,buweiClassSelVal);
              }  else if (xiangMuClassSelLen != 0 && xiangMuClassSelVal !=  "0"  ){
                     //按项目查询
                   var  className =  "xiangmuClass" ;
               fenyeGetMsg(className,xiangMuClassSelVal,current);
                 //查询时将总页数查出来
               getTotalPage(className,xiangMuClassSelVal);
              }  else if (xiangMuClassSelVal ==  "0" ){
                     //默认查询全部,和第一级请选择是查询全部
                   var  className =  "xiangmuClass" ;
               fenyeGetMsg(className,xiangMuClassSelVal,current);
                 //查询时将总页数查出来
               getTotalPage(className,xiangMuClassSelVal);
              }
                //处理页码
          chuliYeMa();
     }
       //处理页码
     function  chuliYeMa(){
          
            var  current = $( "#current"  ).val();
          
            var  shang = current*1 -1;
            var  xia =  current*1 + 1;
            var  str =  ""  ;
            if (current>1){
              str +=  "<a href='javascript:fenye(" +shang+  ");'>上一页</a>&nbsp;"
          }  else {
              str +=  "<a>上一页</a>&nbsp;"
          }
            for ( var  i=1;i<=totalPage;i++){
                if (i == current){
                   str +=  "<a class='" +i+ "'>" +i+  "</a>&nbsp;"
              }  else {
                   str +=  "<a href='javascript:fenye(" +i+  ");'>" +i+ "</a>&nbsp;"
              }
          }
            if (current < totalPage){
              str +=  "<a href='javascript:fenye(" +xia+  ");'>下一页</a><br/>"
          }  else {
              str +=  "<a>下一页</a><br/>"
          }
          $(  "#fenYe" ).html(str);
          }
     
       //获得总页数
     function  getTotalPage(className,id){
          $.ajax({
            url :  '${pageContext.request.contextPath}/SchoolController/findSmTotalPageByClass'  ,
           data:{
                 "className"  :className,
                     "id" :id
            },
            type:  "post" ,
            success:  function (data){
              totalPage = data;
            },
            error:  function (){
              alert(  "查询总页数失败"  );
           },
            async:  false
          });
     }
     
       //分页中获得数据
     function  fenyeGetMsg(className,id,current){
               $.ajax({
                  url :  '${pageContext.request.contextPath}/SchoolController/findMessageByClass'  ,
                 data:{
                     "className"  :className,
                     "id" :id,
                     "current" :current
                  },
                  type:  "post" ,
                  success:  function (data){
                     var  str =  ""  ;
                     for ( var  i=0;i<data.length;i++){
                         str +=  "<a href='${pageContext.request.contextPath}/SchoolController/smYulan.from?id=" +data[i].id+  "' target='_blank'>" +data[i].title+  "</a>&emsp;&emsp;&emsp;"  +data[i].createtime+ "<br/>"
                    }
                      $( "#schoolMessageTableTbody"  ).html(str);
                  },
                  error:  function (){
                 },
                  async:  false
                });
     }

你可能感兴趣的:(js)