js填充html,javascript – 使用JS填充带有div数组的html文件

这是对您的代码的一个小修改,可能对您有所帮助.唯一真正的变化是,在更新pageList之前,需要将不可见的类添加到pageList中的所有项目 – 这可确保在显示下一个集合之前隐藏旧集合.

var pageList = new Array();

var currentPage = 1;

var numberPerPage = 4;

var events = Array.prototype.slice.call(document.querySelectorAll(".events-section__main-event"));

function getNumberOfPages() {

return Math.ceil(events.length / numberPerPage);

}

function nextPage() {

currentPage += 1;

loadList();

}

function previousPage() {

currentPage -= 1;

loadList();

}

function firstPage() {

currentPage = 1;

loadList();

}

function lastPage() {

currentPage = numberOfPages;

loadList();

}

function loadList() {

var begin = ((currentPage - 1) * numberPerPage);

var end = begin + numberPerPage;

for (i = 0; i < pageList.length; i++) {

pageList[i].classList.add("not-visible"); // make the old list invisible

}

pageList = events.slice(begin, end);

drawList();

check();

}

function drawList() {

for (i = 0; i < pageList.length; i++) {

pageList[i].classList.remove("not-visible");

}

}

function check() {

document.getElementById("next").disabled = currentPage == numberOfPages ? true : false;

document.getElementById("previous").disabled = currentPage == 1 ? true : false;

document.getElementById("first").disabled = currentPage == 1 ? true : false;

document.getElementById("last").disabled = currentPage == numberOfPages ? true : false;

}

function load() {

loadList();

}

var numberOfPages = getNumberOfPages();

window.onload = load;

.events-section__main-event {

height: 25px;

width: 50px;

border: 1px black solid;

}

.not-visible {

display: none;

}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值