// JavaScript Document$(function(){ //根据总页数判断,如果小于5页,则显示所有页数,如果大于5页,则显示5页。根据当前点击的页数生成 var maxPage=jQuery("#countPage").text(); var nowPage=jQuery("#nowPage").text(); var index=parseInt(nowPage);//当前页 var var pageCount =parseInt(maxPage) ;//模拟后台总页数 //生成分页按钮 if(pageCount>5){ page_icon(1,5,0); pageGroup(index,pageCount); }else{ //alert("66"); page_icon(1,pageCount,0); pageGroup(index,pageCount); } //点击分页按钮触发 $("#pageGro li").live("click",function(){ if(pageCount > 5){ var pageNum = parseInt($(this).html());//获取当前页数 window.location.href = "/article/search/"+title+"/"+pageNum; pageGroup(pageNum,pageCount); }else{ var indexpage=jQuery(this).text(); window.location.href = "/article/search/"+title+"/"+indexpage; $(this).addClass("on"); $(this).siblings("li").removeClass("on"); } }); //点击上一页触发 $("#pageGro .pageUp").click(function(){ if(pageCount > 5){ if(index>1){ window.location.href = "/article/search/"+title+"/"+(index-1); } }else{ if(index > 1){ window.location.href = "/article/search/"+title+"/"+(index-1); $("#pageGro li").removeClass("on");//清除所有选中 } } }); //点击下一页触发 $("#pageGro .pageDown").click(function(){ if(pageCount > 5){ if(nowPage<pageCount){ window.location.href = "/article/search/"+title+"/"+(index+1); } }else{ if(index< pageCount){ window.location.href = "/article/search/"+title+"/"+(index+1); $("#pageGro li").removeClass("on");//清除所有选中 } } });});//点击跳转页面function pageGroup(pageNum,pageCount){ if(pageCount>5){ switch(pageNum){ case 1: page_icon(1,5,0); break; case 2: page_icon(1,5,1); break; case pageCount-1: page_icon(pageCount-4,pageCount,3); break; case pageCount: page_icon(pageCount-4,pageCount,4); break; default: page_icon(pageNum-2,pageNum+2,2); break; } } if(pageCount<5){ switch(pageNum){ case 1: page_icon(1,pageCount,0); break; case 2: page_icon(1,pageCount,1); break; case pageCount-1: page_icon(1,pageCount,2); break; case pageCount: page_icon(1,pageCount,3); break; } } if(pageCount==5){ switch(pageNum){ case 1: page_icon(1,pageCount,0); break; case 2: page_icon(1,pageCount,1); break; case pageCount-1: page_icon(1,pageCount,3); break; case pageCount: page_icon(1,pageCount,4); break; default: page_icon(1,pageNum+2,2); break; } }}//根据当前选中页生成页面点击按钮function page_icon(page,count,eq){ var ul_html = ""; for(var i=page; i<=count; i++){ ul_html += "<li>"+i+"</li>"; } $("#pageGro ul").html(ul_html); $("#pageGro ul li").eq(eq).addClass("on");}//上一页function pageUp(pageNum,pageCount){ switch(pageNum){ case 1: break; case 2: page_icon(1,5,0); break; case pageCount-1: page_icon(pageCount-4,pageCount,2); break; case pageCount: page_icon(pageCount-4,pageCount,3); break; default: page_icon(pageNum-2,pageNum+2,1); break; }}//下一页function pageDown(pageNum,pageCount){ switch(pageNum){ case 1: page_icon(1,5,1); break; case 2: page_icon(1,5,2); break; case pageCount-1: page_icon(pageCount-4,pageCount,4); break; case pageCount: break; default: page_icon(pageNum-2,pageNum+2,3); break; }}