javascriptページ分け

2036 ワード


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