ajax分页

function loadPageLink(linkObj,page,total,pagesize,method){  
  	var pagelink ="";
  	if(total>0){
	  pagelink = "<div align=\"center\">";
	  var _first = "首页";
	  var _previous = "上一页";
	  var _next = "下一页";
	  var _last = "末页";
	  var start = page - 4;
 	  var end = page + 4;
 	  if(start <= 1) {
  		 start = 1;
         end = start + 9;
 	  }
 	  if(end >= total) {
	 	 end = total;
	 	 start = end - 9;
	  }
	  if(start <= 0) {
		 start = 1;
	  }
	  var previous = (page - 1 > 0 ? (page - 1) : 1);
      var next = ((page + 1) < total ? (page + 1): total);
	  pagelink  = (pagelink + "<div align=\"center\">")	  
 	  pagelink  = (pagelink + "<a href=\"javascript:"+method+"(1)\" title=\""+_first+"\">"+_first+"</a>");
      pagelink  = (pagelink+"&nbsp;<a href=\"javascript:"+method+"("+previous+")\" title=\""+_previous+"\">"+_previous+"</a>");
      for(var i=start;i<=end;i++){
        if(i==page){
	  	  pagelink = (pagelink + "&nbsp;<strong>"+i+"</strong>");
	    }else{
	     pagelink  = (pagelink+"&nbsp;<a href=\"javascript:"+method+"("+i+")\">"+i+"</a>");
	   }
      }
      pagelink  = (pagelink+"&nbsp;<a href=\"javascript:"+method+"("+next+")\" title=\""+_next+"\">"+_next+"</a>");
      pagelink  = (pagelink+"&nbsp;<a href=\"javascript:"+method+"("+total+")\" title=\""+_last+"\">"+_last+"</a>");
	  pagelink  = (pagelink + "</div>")	  
	  pagelink  = (pagelink+"<br/><div align=\"center\">当前第<strong>"+page+"</strong>页/一共<strong>"+total+"</strong>页</div>");
	  pagelink  = (pagelink + "</div>")	  
    }else{
	   pagelink = "没有符合要求的数据!";
	}
    linkObj.innerHTML = pagelink;
  }

你可能感兴趣的:(Ajax)