HTML和Javascript搜索结果分页-限制显示结果页面的数量
使用HTML和javascript,我有一些基本的搜索结果分页,虽然可以工作,但如果有数百个结果,我最终可以使用如下分页: 我想限制这只显示1-10,然后11-10等,有人能告诉我一个如何做到这一点的例子吗HTML和Javascript搜索结果分页-限制显示结果页面的数量,javascript,html,Javascript,Html,使用HTML和javascript,我有一些基本的搜索结果分页,虽然可以工作,但如果有数百个结果,我最终可以使用如下分页: 我想限制这只显示1-10,然后11-10等,有人能告诉我一个如何做到这一点的例子吗 <div class="row igs-learning-paths-pagination-row"> <div class="col-12 d-flex justify-content-center" >
<div class="row igs-learning-paths-pagination-row">
<div class="col-12 d-flex justify-content-center" >
<ul class="pagination pagination-info">
<li class="page-item">
<a href="javascript:void(0)" onclick="displayPreviousPage()" class="igs-learning-paths-pagingation-text igs-text-uppercase">
@Umbraco.GetDictionaryValue("Common Prev", "Prev..").ToUpper()
</a>
</li>
@for (int i = 0; i <= @Model.Results.Count() / numberPerPage; i++)
{
<li class="@(i == 0 ? "active" : null) page-item non-generate-page-item" id="page-list-item-@(i)" style="border-radius:16px;">
<a class="page-link" id="page-number-@(i)" href="javascript:void(0)" onclick="displayPages(@(i))">@(i + 1)</a>
</li>
}
<li class="page-item" alt="Go forward a page" title="Go forward a page">
<a href="javascript:void(0)" alt="Go forward a page" title="Go forward a page"
onclick="displayNextPage()"
class="igs-learning-paths-pagingation-text igs-text-uppercase search-result-margin">
@Current.UmbracoHelper.GetDictionaryValue("Common Next", "Next..").ToUpper()
</a>
</li>
</ul>
</div>
</div>
<script>
var numberPerPage = @numberPerPage;
var totalResults = @Model.Results.Count();
var maxPage = Math.floor(totalResults / numberPerPage);
var currentPage = 0;
var previousPage = 0;
function displayNextPage() {
if (currentPage == maxPage) return;
currentPage = currentPage + 1
displayPages(currentPage);
}
function displayPreviousPage() {
if (currentPage == 0) return;
currentPage = currentPage - 1
displayPages(currentPage);
}
function displayPages(pageToDisplay) {
$(".page-search-hider").hide();
currentPage = pageToDisplay;
if (!pageToDisplay) {
pageToDisplay = 0
}
else {
var skip = pageToDisplay * numberPerPage;
pageToDisplay = skip+1;
}
var newNumberPerPage = numberPerPage;
document.getElementById("page-list-item-" + previousPage).classList.remove("active")
previousPage = currentPage;
document.getElementById("page-list-item-" + currentPage).classList.add("active")
for (var i = 0; i <= newNumberPerPage; i++) {
var result = pageToDisplay + i;
$("#pageId-" + result).show();
$("#pageId-" + @(pageIdCount)).hide();
}
}
-
@对于(int i=0;i
常量页码=[1,2,3,4,5,6,7,8,9,10];
常量maxPageLimit=5;
设upperPageIndex=maxPageLimit;
设currentPageIndex=0;
让displayPages=PageNumber.slice(currentPageIndex,upperPageIndex);//slice(startIndex,endIndex);
console.log(显示页面)
//如果currentPageIndex=2,则在浏览时再显示2个
upperPageIndex+=2;//如果需要,可以将2设为常量
currentPageIndex+=2;
displayPages=PageNumber.slice(currentPageIndex,upperPageIndex);
console.log(displayPages)
@for(int i=0;i