从phpcms系统的分页函数改过来的。
/** * pages 总页数 * curr_page 当前分页 * url URL规则 * eg:mypage(20,10,"aaa.php") */ function mypage(pages,curr_page,url){ var setpages = 10; var page = setpages + 1; var offset = setpages/2 - 1; var from = curr_page - offset; var to = curr_page + offset; var more = 0; if(page >= pages) { from = 2; to = pages-1; } else { if(from <= 1) { to = page-1; from = 2; } else if(to >= pages) { from = pages-(page-2); to = pages-1; } more = 1; } var multipage = ''; if(curr_page > 0) { if(curr_page > 1) { multipage += '<a href="'+ url+'?page='+(curr_page-1) +'">上一页</a>'; } if(curr_page == 1) { multipage += '<a class="current">1</a>'; } else if(curr_page > 6 && more) { multipage += '<a href="'+ url +'">首页</a>...'; } else { multipage += '<a href="'+ url +'">1</a>'; } } for(i = from; i <= to; i++) { if(i != curr_page) { multipage += '<a href="'+ url+'?page='+i +'">'+ i +'</a>'; } else { multipage += '<a class="current">'+ i +'</a>'; } } if(curr_page < pages) { if(curr_page < pages - 5 && more) { multipage += '...<a href="'+ url+'?page='+pages +'">尾页</a><a href="'+ url+'?page='+(curr_page+1) +'">下一页</a>'; } else { multipage += '<a href="'+ url+'?page='+pages +'">'+ pages +'</a><a href="'+ url+'?page='+(curr_page+1) +'">下一页</a>'; } } else if(curr_page == pages) { multipage += '<a class="current">'+ pages +'</a>'; } else { multipage += '<a href="">'+ pages +'</a><a href="'+ url+'?page='+(curr_page+1) +'">下一页</a>'; } return multipage; }
有朋自远方来...评论一下呗O(∩_∩)O