js分页不利于 seo
试试 我写的这个吧
/// <summary>
/// 生成HTML分页链接(By Yipeng)
/// </summary>
/// #pager{color:#2E6AB1;font-size:12px;line-height:200%;text-align:center;margin:25px 0}#pager a{border:1px solid #9AAFE5;color:#2E6AB1;margin-right:4px;text-decoration:none;padding:2px 5px}#pager span.current{background-color:#2E6AB1;border:1px solid navy;color:#FFF;font-weight:700;margin-right:4px;padding:2px 5px}
/// <param name="RecordsTotal">总记录数</param>
/// <param name="pageSize">每页显示记录数</param>
/// <param name="currentPage">当前页码</param>
/// <param name="pageNumSize">一次性显示的页码数量</param>
/// <param name="linkFormat">链接格式 如:"Index.aspx?page={0}、Index/page/{0}"</param>
/// <param name="maxPageSize"> 最多显示的页数(为了性能需要)</param>
/// <returns></returns>
public static string PrintPagerLinks(int RecordsTotal, int pageSize, int currentPage, int pageNumSize, string linkFormat, int? maxPageSize)
{
// "<div id=\"pager\"><a onclick=\"\" href=\"/page8\">< Prev</a><a onclick=\"\" href=\"/page1\">1</a>··· <a onclick=\"\" href=\"/page4\">4</a><a onclick=\"\" href=\"/page5\">5</a><a onclick=\"\" href=\"/page6\">6</a><a onclick=\"\" href=\"/page7\">7</a><a onclick=\"\" href=\"/page8\">8</a><span class=\"current\">9</span><a onclick=\"\" href=\"/page10\">10</a><a onclick=\"\" href=\"/page11\">11</a><a onclick=\"\" href=\"/page12\">12</a><a onclick=\"\" href=\"/page13\">13</a><a onclick=\"\" href=\"/page14\">14</a>··· <a onclick=\"\" href=\"/page200\">200</a><a onclick=\"\" href=\"/page10\">Next ></a></div>";
StringBuilder html = new StringBuilder();
int totalPageNum = (int)Math.Ceiling((double)RecordsTotal / (double)pageSize);
if (maxPageSize.HasValue && totalPageNum > maxPageSize)
totalPageNum = maxPageSize.Value;
if (totalPageNum == 1)
{
return string.Empty;
}
html.Append("<div id=\"pager\">");
if (currentPage > 1)
{
html.AppendFormat("<a href=\"{0}\">上一页</a>", string.Format(linkFormat, currentPage - 1));
}
int startNum = 1;
int endNum = totalPageNum;
if (pageNumSize < totalPageNum)
{
startNum = currentPage - (pageNumSize / 2);
startNum = startNum < 1 ? 1 : (startNum + pageNumSize > totalPageNum ? totalPageNum - pageNumSize : startNum);
endNum = startNum + pageNumSize;
}
if (startNum > 1)
{
html.AppendFormat("<a href=\"{0}\">{1}</a>…", string.Format(linkFormat, 1), 1);
}
for (int i = startNum; i <= endNum; i++)
{
if (currentPage == i)
{
html.AppendFormat("<span class=\"current\">{0}</span>", i);
}
else
{
html.AppendFormat("<a href=\"{0}\">{1}</a>", string.Format(linkFormat, i), i);
}
}
if (endNum < totalPageNum)
{
html.AppendFormat("…… <a href=\"{0}\">{1}</a>", string.Format(linkFormat, totalPageNum), totalPageNum);
}
if (currentPage < totalPageNum)
{
html.AppendFormat("<a href=\"{0}\">下一页</a>", string.Format(linkFormat, currentPage + 1));
}
html.Append("</div>");
return html.ToString();
}