js写分页

<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);
					});

    		}			
		}
	});
}	

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值