繁星点点滴滴
好象没太多意义,那个currint应该就是10除2的结果,整个代码就大概是要显示从currentPage-5到currentPage+5之间这10页,就相当于1234567891011121314151617string output = "";int num = 10;if (totalPages < num) num = totalPages-1;//如果总页数不够10int currint = num / 2;int min = (currentPage >currint ? currentPage - currint : 1);//起始int max = (currentPage + currint > totalPages ? totalPages : currentPage + currint);//结束 //为避免currentpage小于5时,以及避免最后几页显示不到10项,加上下面两行if (max <= num) max = num+1;if (max - min < num) min = max - num; if (currentPage > totalPages) currentPage = totalPages;for(int i=min;i<max;i++){string css=(i==currentPage?"cpb":"pageLink");output.AppendFormat("<a class='{4}' href='{0}?pageIndex={1}&pageSize={2}'>{3}</a> ", redirectTo, i, pageSize, i,css);} 附上修改前后的图(最前的数字为当前页,为简单我直接把当前页用[]标出了)