js分页页码算法

时间:2023-03-09 16:02:05
js分页页码算法
function get_hs_page(cur_page, total_page) {
var result = "";
for(var i = ; i <= total_page; i++) {
if(i == && cur_page - > ) {
i = cur_page - ;
}else if(i == cur_page + && cur_page + < total_page) {
i = total_page - ;
}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为总页数。