js写分页

来源:互联网 发布:淘宝挣钱 编辑:程序博客网 时间:2024/06/18 07:12
<a href="#" onclick="getPrice(1,10)">首页</a>   <a href="#" onclick="forward()">上一页</a>   <a href="#" class="page_first" id="currentPage"></a>     <a href="#" id="currentPageAdd1" onclick="changePage(this.id)"></a>  <a href="#" id="currentPageAdd2" onclick="changePage(this.id)"></a>  <a href="#" id="currentPageAdd3" onclick="changePage(this.id)"></a>  <a href="#" id="currentPageAdd4" onclick="changePage(this.id)"></a>     <a href="#" onclick="back()">下一页</a>   <a href="#" onclick="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);});    }}});}

原创粉丝点击