javascript分页条

//返回分页html
//@param page 当前页
//@param pageCount 总共页
//fuctionName 点击执行函数名称
function pageBar( page,pageCount,fuctionName){
					var getPage =parseInt(page);
					var  pageCount=parseInt(pageCount);
					if( getPage < 5 ){
						var start  = 1;
						var startStr = "";
					}else{
						var start = getPage - 2;
						var startStr =" <a href=\"javascript:void(0);\" onclick=\""+fuctionName+"("+(parseInt(getPage)-1).toString()+");\">上一页</a><a href=\"javascript:void(0);\"  onclick=\""+fuctionName+"("+1+");\" >1</a>...";
					}
					if( getPage < pageCount - 3){
						var ends = parseInt(getPage) + 2;
						var endsStr ="...<a href=\"javascript:void(0);\" onclick=\""+fuctionName+"("+pageCount+");\">"+pageCount+"</a><a href=\"javascript:void(0);\"  onclick=\""+fuctionName+"("+(parseInt(getPage)+1).toString()+");\" >下一页</a>";
						
					}else{
						var ends = pageCount;
						var endsStr = "";
					}
					var mainStr = [];
					for(var i = start ;i<=ends ;i++ ){
						if(i==getPage){
							mainStr[i] = "<a href=\"javascript:void(0)\" class=\"cur\">"+i+"</a>";
						}else{
							mainStr[i] = "<a href=\"javascript:void(0)\" onclick=\""+fuctionName+"("+i+");\">"+i+"</a>";
						}
						
					}
					if(pageCount>1){
						var curPageStr = '&nbsp;'+getPage+'/'+pageCount;
					}else{
						var curPageStr="";
					}
					var pageStr = startStr + mainStr.join(" ") + endsStr+curPageStr;
					return pageStr;
}


你可能感兴趣的:(JavaScript)