js写分页

xiaoxiao2021-02-28  22

<a href="#" οnclick="getPrice(1,10)">首页</a> <a href="#" οnclick="forward()">上一页</a> <a href="#" class="page_first" id="currentPage"></a> <a href="#" id="currentPageAdd1" οnclick="changePage(this.id)"></a> <a href="#" id="currentPageAdd2" οnclick="changePage(this.id)"></a> <a href="#" id="currentPageAdd3" οnclick="changePage(this.id)"></a> <a href="#" id="currentPageAdd4" οnclick="changePage(this.id)"></a> <a href="#" οnclick="back()">下一页</a> <a href="#" οnclick="getPrice(-1,10)">末页</a> <i>共<i id="pageSum"></i>页</i> <SCRIPT type="text/javascript"> function changePage(val){ //alert(val); currentPage=$("#"+val).text(); //alert(currentPage); currentPage=parseInt(currentPage); getPrice(currentPage,"10"); } function forward(){ var currentPage=$("#currentPage").text(); currentPage=parseInt(currentPage); if(currentPage>1){ currentPage=currentPage-1; } getPrice(currentPage,"10"); } function back(){ var currentPage=$("#currentPage").text(); var pageSum=$("#pageSum").text(); if(parseInt(currentPage)<parseInt(pageSum)){ currentPage=parseInt(currentPage)+1; } getPrice(currentPage,"10"); } function getPrice(currentPage,pageSize){ //alert(currentPage); $("#currentPageAdd1").text(parseInt(currentPage)+1); $("#currentPageAdd2").text(parseInt(currentPage)+2); $("#currentPageAdd3").text(parseInt(currentPage)+3); $("#currentPageAdd4").text(parseInt(currentPage)+4); if(currentPage==-1){ currentPage=$("#pageSum").text(); } var _url = "<%=request.getContextPath()%>/user/getDataFromURL.html"; $.ajax({ type: 'POST', url: _url, data: {"currentPage":currentPage,"pageSize":pageSize}, dataType: "json", success: function(data){ $("#pricehangqingtongji").empty(); if (data.success==1){ //alert(data.price.totalCount); var pageSum=0; if(data.price.rows.length%pageSize+"".indexOf(".")==-1){ pageSum=data.price.totalCount/pageSize+""; pageSum=pageSum.split(".")[0]; }else{ pageSum=parseInt(data.price.totalCount/pageSize)+1+""; pageSum=pageSum.split(".")[0]; } $("#pageSum").text(pageSum); $("#currentPage").text(currentPage); $.each(data.price.rows,function(index,value){ var li =''; li +='<ul class="list-con">'; li +=' </ul>'; $("#pricehangqingtongji").append(li); }); } } }); }
转载请注明原文地址: https://www.6miu.com/read-1950022.html

最新回复(0)