js分页页码算法
function get_hs_page(cur_page, total_page) { var result = ""; for(var i = 1; i <= total_page; i++) { if(i == 2 && cur_page - 6 > 1) { i = cur_page - 6; }else if(i == cur_page + 6 && cur_page + 6 < total_page) { i = total_page - 1; }else{ if(i == cur_page){ result += "<li><a style='background-color:#e7e7e7;' href='/topic?page="+i+"&type=hs'>"+i+"</a></li>"; }else{ result += "<li><a href='/topic?page="+i+"&type=hs'>"+i+"</a></li>"; } } } return result; }
注意:cur_page为当前页,total_page为总页数。