js写分页

9/6/2015来源:Java教程人气:1560

js写分页

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

<divid="fenYe"></div>js://四级下拉关系配合数据$(function(){//进来就查询全部fenye(1);chuliYeMa();});vartotalPage;//分页方法functionfenye(current){if(current ==undefined){current = 1;}//将点击后的页放入隐藏框里$("#current").val(current);//详细原因varxxYuanyinSelLen = $("#xxYuanyinSel option").length;varxxYuanyinSelVal = $("#xxYuanyinSel option:selected").val();//详细部位varxxbuweiSelLen = $("#xxbuweiSel option").length;varxxbuweiSelVal = $("#xxbuweiSel option:selected").val();//部位varbuweiClassSelLen = $("#buweiClassSel option").length;varbuweiClassSelVal = $("#buweiClassSel option:selected").val();//项目varxiangMuClassSelLen = $("#xiangMuClassSel option").length;varxiangMuClassSelVal = $("#xiangMuClassSel option:selected").val();//刷新表数据if(xxYuanyinSelLen != 0 && xxYuanyinSelVal !="0"){//按详细原因查询varclassName ="xxyuanyin"; fenyeGetMsg(className,xxYuanyinSelVal,current); //查询时将总页数查出来 getTotalPage(className,xxYuanyinSelVal);}else if(xxbuweiSelLen != 0 && xxbuweiSelVal !="0"){//按详细部位查询varclassName ="xxbuwei"; fenyeGetMsg(className,xxbuweiSelVal,current); //查询时将总页数查出来 getTotalPage(className,xxbuweiSelVal);}else if(buweiClassSelLen != 0 && buweiClassSelVal !="0"){//按部位查询varclassName ="buweiClass"; fenyeGetMsg(className,buweiClassSelVal,current); //查询时将总页数查出来 getTotalPage(className,buweiClassSelVal);}else if(xiangMuClassSelLen != 0 && xiangMuClassSelVal !="0"){//按项目查询varclassName ="xiangmuClass"; fenyeGetMsg(className,xiangMuClassSelVal,current); //查询时将总页数查出来 getTotalPage(className,xiangMuClassSelVal);}else if(xiangMuClassSelVal =="0"){//默认查询全部,和第一级请选择是查询全部varclassName ="xiangmuClass"; fenyeGetMsg(className,xiangMuClassSelVal,current); //查询时将总页数查出来 getTotalPage(className,xiangMuClassSelVal);}//处理页码 chuliYeMa();}//处理页码functionchuliYeMa(){varcurrent = $("#current").val();varshang = current*1 -1;varxia = current*1 + 1;varstr ="";if(current>1){str +="<a href='javascript:fenye("+shang+");'>上一页</a>&nbsp;"}else{str +="<a>上一页</a>&nbsp;"}for(vari=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);}//获得总页数functiongetTotalPage(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});}//分页中获得数据functionfenyeGetMsg(className,id,current){ $.ajax({ url :'${pageContext.request.contextPath}/SchoolController/findMessageByClass', data:{ "className":className, "id":id, "current":current }, type:"post", success:function(data){ varstr =""; for(vari=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});}