本文实例讲述了jQuery实现的分页功能。分享给大家供大家参考,具体如下:

1、分页栏HTML码

<div class="g-cf g-pagerwp">
  <div style="visibility:hidden" class="g-pager">
  </div>
</div>

2、CSS样式文件

.g-cf:after {clear: both;content: "";display: table;}
.g-cf {zoom:1;}
/*分页*/
.g-pager{ text-align:center; color: #111111; font: 12px/1.5em Arial,Tahoma; float: right;}
.g-pager a,.g-pager input{ cursor:pointer; border:solid 1px #0F71BE; padding:1px 4px; color:#0F71BE; margin:0 2px; vertical-align:middle; }
.g-pager a.cur,.g-pager a:hover{ background-color:#0F71BE; color:#fff}
.g-pager a.no{ border-color:#A3A3A3; color:#A3A3A3; background-color:#E4F2F9}
.g-pager span{ margin-right:10px; }
.g-pager input{ cursor:default; width:28px; padding:1px 2px; }
.g-pagerwp{ height:23px; line-height:23px;padding:5px; margin-bottom:10px; border: 1px solid #DDDDDD;}
.g-pagerwp .g-btn{ vertical-align:top}

3、JS脚本文件

① 引用JQuery和分页脚本

<script src="/UploadFiles/2021-04-02/jquery-1.6.2.js">

② 编写jquery.PageBar.js脚本

/**************************/
//JQuery分页栏
/**************************/
$.fn.pageBar = function(options) {
  var configs = {
    PageIndex: 1,
    PageSize: 15,
    TotalPage: 0,
    RecordCount: 0,
    showPageCount: 4,
    onPageClick: function(pageIndex) {
      return false;  //默认的翻页事件
    }
  }
  $.extend(configs, options);
  var tmp = "",
  i = 0,
  j = 0,
  a = 0,
  b = 0,
  totalpage = parseInt(configs.RecordCount / configs.PageSize);
  totalpage = configs.RecordCount % configs.PageSize > 0 "<span>总记录数:" + configs.RecordCount + "</span > ";
  tmp += " <span>页数:" + totalpage + "</span>";
  if (configs.PageIndex > 1) {
    tmp += "<a><</a>"
  } else {
    tmp += "<a class=\"no\"><</a>"
  }
  tmp += "<a>1</a>";
  if (totalpage > configs.showPageCount + 1) {
    if (configs.PageIndex <= configs.showPageCount) {
      i = 2;
      j = i + configs.showPageCount;
      a = 1;
    } else if (configs.PageIndex > totalpage - configs.showPageCount) {
      i = totalpage - configs.showPageCount;
      j = totalpage;
      b = 1;
    } else {
      var k = parseInt((configs.showPageCount - 1) / 2);
      i = configs.PageIndex - k;
      j = configs.PageIndex + k + 1;
      a = 1;
      b = 1;
      if ((configs.showPageCount - 1) % 2) {
        i -= 1
      }
    }
  }
  else {
    i = 2;
    j = totalpage;
  }
  if (b) {
    tmp += "..."
  }
  for (; i < j; i++) {
    tmp += "<a>" + i + "</a>"
  }
  if (a) {
    tmp += " ... "
  }
  if (totalpage > 1) {
    tmp += "<a>" + totalpage + "</a>"
  }
  if (configs.PageIndex < totalpage) {
    tmp += "<a</a>"
  } else {
    tmp += "<a class=\"no\"</a>"
  }
  tmp += "<input type=\"text\" /><a>Go</a>"
  var pager = this.html(tmp)
  var index = pager.children('input')[0]
  pager.children('a').click(function() {
    var cls = $(this).attr('class');
    if (this.innerHTML == '<') {
      if (cls != 'no') {
        configs.onPageClick(configs.PageIndex - 2)
      }
    } else if (this.innerHTML == '>') {
      if (cls != 'no') {
        configs.onPageClick(configs.PageIndex)
      }
    } else if (this.innerHTML == 'Go') {
      if (!isNaN(index.value)) {
        var indexvalue = parseInt(index.value);
        indexvalue = indexvalue < 1 "htmlcode">
$(document).ready(function() {
  //设置分页信息
  var pageOptions = {
    AllowPaging: true,
    PageIndex: 1,    //设置当前页码
    PageSize: 15,    //设置分页大小
    RecordCount: 1092, //设置数据总数
    TotalPage: 73,   //设置总页数
    showPageCount: 4,
    onPageClick: function(pageIndex) {
    alert("您点击了第" + parseInt(pageIndex + 1) + "页");  //自定义您的翻页事件
      return false;
    }
  }
  //初始化分页栏
  $('.g-pagerwp .g-pager').css('visibility', 'visible').pageBar(pageOptions);
})

更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery扩展技巧总结》、《jQuery表格(table)操作技巧汇总》、《jQuery常见经典特效汇总》、《jquery选择器用法总结》及《jQuery常用插件及用法总结》

希望本文所述对大家jQuery程序设计有所帮助。

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。