数据分页

一.数据分页
1.创建页码
1.使用if、else语句对页码进行前缩、后缩以及前后缩;并进行传值;
if (i == 2 && current - 5 > i) {
i = current - 1;
str += “

  • ”;
    }
    else if (i == current + 5 && current + 5 < totle) {
    i = totle - 1;
    str += “
  • ”;
    }
    else {
    if (current == i) {
    str += “
  • ” + i + “
  • ”;
    }
    else {
    str += “
  • ” + i + “
  • ”;
    }
    }
    }
    2.使用onclick事件对页码进行鼠标操控跳转以及上、下一页的跳转
    上一页:
    his.back.onclick = function () {
    that.pageNow–;
    if (that.pageNow < 1) {
    that.pageNow = 1;
    }
    that.createli(that.pageNow, that.pagetotleNum);
    that.getliNumAddEvent();
    that.getNowData(that.pageNow);
    that.createNowDataEle();
    }
    下一页:
    this.advance.onclick = function () {
    that.pageNow++;
    if (that.pageNow > that.pagetotleNum) {
    that.pageNow = that.pagetotleNum;
    }
    that.createli(that.pageNow, that.pagetotleNum);
    that.getliNumAddEvent();
    that.getNowData(that.pageNow);
    that.createNowDataEle();
    }
    点击数据页码跳转
    getliNumAddEvent: function () {
    var that = this;
    var lilist = document.getElementsByClassName(“linum”);
    for (var i = 0; i < lilist.length; i++) {
    lilist[i].onclick = function () {
    Paging.pageNow = parseInt(this.innerHTML);
    Paging.createli(Paging.pageNow, Paging.pagetotleNum);
    Paging.getliNumAddEvent();
    that.getNowData(that.pageNow);
    that.createNowDataEle();
    }
    }
    },
    3.在当前页创建并加载数据
    createNowDataEle: function () {
    this.newslist.innerHTML=""
    for (var i = 0; i < this.pageNum; i++) {
    var div = document.createElement(“div”);
    div.className = “divlist”;
    使用key做键进行数据的传值
    for (var key in this.pageNowData[i]) {
    var childdiv = document.createElement(“div”);
    childdiv.className = “childdiv”;
    childdiv.innerHTML = this.pageNowData[i][key];
    div.appendChild(childdiv);
    }
    this.newslist.appendChild(div);
    }
    },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值