如何创建像stackoverflow这样的分页?
答案 0 :(得分:7)
您没有说明您正在使用哪种服务器端技术,但如果您想要一个纯客户端解决方案,您可以查看jQuery Pagination插件。这是一个demo page。
答案 1 :(得分:2)
只需在页面中包含jquery和jquery分页插件,然后使用它,
$(document).ready(function() {
$(".pager").pagination(300, {
callback: pagecallback,
current_page: 0,
items_per_page: 5,
num_display_entries: 5,
next_text: 'Next',
prev_text: 'Prev',
num_edge_entries: 1
});
});
.pager {
margin-bottom: 10px;
margin-top: 10px;
}
.page-numbers {
border: 1px solid #CCCCCC;
color: #808185;
display: block;
float: left;
font-family: Trebuchet MS, Helvetica, sans-serif;
font-size: 130%;
margin-right: 3px;
padding: 4px 4px 3px;
text-decoration: none;
}
.page-numbers.desc {
border: medium none;
}
.page-numbers:hover {
text-decoration: none;
}
.pager a {
color: #808185;
cursor: pointer;
text-decoration: none;
outline: none;
}
.pager a:hover {
text-decoration: underline;
}
.pager a:visited {
color: #808185;
outline: none;
}
.page-numbers.next,
.page-numbers.prev {
border: 1px solid #CCCCCC;
}
.page-numbers.current {
background-color: #808185;
border: 1px solid #808185;
color: #FFFFFF;
font-weight: bold;
}
.page-numbers.dots {
border: 1px solid #FFFFFF;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="pager" id="Pagination">
<!-- the container for your first pagination area -->
</div>
答案 2 :(得分:1)
使用Jquery插件分页:
答案 3 :(得分:1)
您可以使用twitter bootstrap创建分页,其代码少于10行
答案 4 :(得分:0)
答案 5 :(得分:0)
您也可以使用此功能:
function makePaging(totalPages, pageIndex) {
var oPaging, i, j, k;
var totalPages = parseInt(totalPages);
pageIndex++;
i = pageIndex;
j = pageIndex - 1;
k = pageIndex + 1;
var oBefore, oAfter;
oBefore = "";
oAfter = "";
while (j != 0 && j != i - 6) {
oBefore = "<a class='Page' href='#' data-index='" + (j - 1) + "'>" + j + "</a> " + oBefore;
j--;
}
for (; k < totalPages + 1 && k < i + 6; k++) {
oAfter += "<a class='Page' href='#' data-index='" + (k - 1) + "'>" + k + "</a> ";
}
oPaging = oBefore + "<a class='CurPage' href='#' rel='' style='color:Red;'>" + i.toString() + "</a> " + oAfter;
return oPaging;
}