jquery前端简单分页

How to create easy pagination with jQuery jQuery pagination. All we know, that when we facing with necessarity to display large amount of data – we starting thinking about adding pagination. So we split all our content to several pages. And in this case – each page contain some part of our information. As usual this is server-side pagination, where we extracting necessary amount data from database for each page. But commonly, in case of small (or middle) data sets – we don`t need such pagination. And we can just use user-side pagination using javascript to manage with our pages. Today I will show you how to create such pagination.

如何使用jQuery创建简单的分页 jQuery分页。 我们所知道的是,当我们需要显示大量数据时,我们开始考虑添加分页。 因此,我们将所有内容分为几页。 在这种情况下,每个页面都包含我们的部分信息。 与往常一样,这是服务器端分页,在此我们从数据库中为每个页面提取必要的数据量。 但是通常,在数据集较小(或中等)的情况下,我们不需要这种分页。 而且,我们可以只使用使用JavaScript的用户端分页来管理我们的页面。 今天,我将向您展示如何创建这种分页。

Here are samples and downloadable package:

以下是示例和可下载的软件包:

现场演示

[sociallocker]

[社交储物柜]

打包下载

[/sociallocker]

[/ sociallocker]

Ok, download the source files and lets start coding !

好的,下载源文件并开始编码!

步骤1. XHTML (Step 1. XHTML)

Here are our main HTML file:

这是我们的主要HTML文件:

index.html(由于进行了一些更正而已更新) (index.html (updated due few corrections))


<link rel="stylesheet" href="css/main.css" type="text/css" />
<script src="js/jquery.min.js"></script>
<script src="js/imtech_pager.js"></script>
<div class="example"><h3><a href="#">Paragraph pagination sample</a></h3><div id="content"><div class="z">Sergey LUKYANENKO - The Boy and the Darkness - Chapter 1. The Sun Kitten.</div><div class="z">Everything happened because I got ill.</div><div class="z">It was already two in the afternoon, and I was lying in bed flicking through "Peter Pan" - I must have read it a hundred times over. I had long since pulled off the bandage my mother had tied around my neck in the morning, and thrown it into a corner. I simply can't understand - how can cotton wool soaked in vodka possibly help a cough? I don't argue with my mum, of course, but after she leaves I look after myself in my own way - namely, lie in bed with a book and wait for my germs to get tired of such a boring method of passing time. It usually helps - perhaps not at once, but after a day or three. A good thing, really, that the street outside looked quite miserable - the sun poking out for brief moments, only to make room for a patchy, nasty drizzle. Though, the sun never actually peeked into the room - our house is so unfortunately placed that it is in the shadows of the new nine-floor high-rises on every side. "The only use for such a flat is to grow mushrooms", - dad used to say, back when he still lived with us.</div><div class="z">I put my book down on the floor next to the bed, and lay on my back. Perhaps, had I shut my eyes now, nothing would have happened. But there I was, lying staring at the ceiling and listening to the ticking of the clock in the hallway.</div><div class="z">And a speck of sunlight jumped into the room through the glass. Small - the size of my hand - but surprisingly bright. As though the window was open, with bright summer sun outside. Someone was probably playing with a mirror on the balcony of the house across the street.</div><div class="z">The rabbit floated across the ceiling, climbed down a wall, made a vase on the dressing-table glint, and stopped, shaking slightly, on my headrest.</div><div class="z">- Don't go, - I said for some reason, knowing that in a moment the mirror would shift and the rabbit would leave my room forever. - Stay...</div><div class="z">And that's when it all started.</div><div class="z">The sun rabbit tore free of the bed and floated in the air. I didn't even realise at first that such things don't happen. It was only when the flat spot hanging in the air started puffing out to form a fuzzy orange ball that I understood - a miracle had happened.</div><div class="z">Four paws stretched from orange glowing fur, followed by a tail and a head. Green cat eyes blinked and gazed at me steadily. And overall, in fact, the rabbit looked more like a kitten than anything else. Except he was hanging in the air, glowing, and seemed light as the fairy fluff that floats away if one blows gently.</div><div class="z">- Hello, - purred the kitten. - Thank you for the invitation.</div><div class="z">I closed my eyes for a second, but when I opened them again, the kitten hadn't disappeared. In fact, he'd flown closer.</div><div class="z">- I don't believe in fairy tales, - I told myself. - I'm grown up now.</div><div class="z">- Well, compared to the girl who was holding the True Mirror, you are quite grown up, - declared the kitten, unperturbed, and lowered himself onto the blanket. I glanced over - to see if there would be smoke - but everything seemed all right. I could feel warmth with my chest, but not strong. And the kitten tilted his head and added: - But one can't really call you adult, either. How old are you? Ten, maybe?</div><div class="z">- Fourteen, - I replied, finding myself calming down at such a mundane question. - Who're you?</div><div class="z">- A sun rabbit, - replied the kitten, examining himself curiously. - What an appearance.. do I look like one?</div><div class="z">- <b>Like</b> what?</div><div class="z">- Like a <p style="font-weight:bold;color:red;">sun</p> rabbit.</div><div class="z">- More like a kitten.</div><div class="z">- Hardly better, - stated the Kitten sadly and stretched out. And I didn't think of anything better than repeating:</div><div class="z">- Who're you?</div><div class="z">- But we have already arrived at a consensus! - said the Kitten with sudden hurt. - A sun rabbit, or more precisely - a kitten, because I look far more like one! What is there not to understand?</div><div class="z">I found myself tongue-tied. Well, naturally, a small green animal that eats stones would simply be - a small green stone-eater. Simple. And a sun rabbit is a sun kitten, because he looks nothing like a rabbit.</div><div class="z">- So you mean - any rabbit can come to life if one just calls it? - I asked cautiously. For some reason it seemed to me the Kitten would be hurt at the question again. But he just shook his head proudly:</div><div class="z">- As if! Any! Only True Light, reflected in a True Mirror, can come to life.</div></div><div id="pagingControls"></div>
</div>
<script type="text/javascript">
var pager = new Imtech.Pager();
$(document).ready(function() {pager.paragraphsPerPage = 5; // set amount elements per pagepager.pagingContainer = $('#content'); // set of main containerpager.paragraphs = $('div.z', pager.pagingContainer); // set of required containerspager.showPage(1);
});
</script>

<link rel="stylesheet" href="css/main.css" type="text/css" />
<script src="js/jquery.min.js"></script>
<script src="js/imtech_pager.js"></script>
<div class="example"><h3><a href="#">Paragraph pagination sample</a></h3><div id="content"><div class="z">Sergey LUKYANENKO - The Boy and the Darkness - Chapter 1. The Sun Kitten.</div><div class="z">Everything happened because I got ill.</div><div class="z">It was already two in the afternoon, and I was lying in bed flicking through "Peter Pan" - I must have read it a hundred times over. I had long since pulled off the bandage my mother had tied around my neck in the morning, and thrown it into a corner. I simply can't understand - how can cotton wool soaked in vodka possibly help a cough? I don't argue with my mum, of course, but after she leaves I look after myself in my own way - namely, lie in bed with a book and wait for my germs to get tired of such a boring method of passing time. It usually helps - perhaps not at once, but after a day or three. A good thing, really, that the street outside looked quite miserable - the sun poking out for brief moments, only to make room for a patchy, nasty drizzle. Though, the sun never actually peeked into the room - our house is so unfortunately placed that it is in the shadows of the new nine-floor high-rises on every side. "The only use for such a flat is to grow mushrooms", - dad used to say, back when he still lived with us.</div><div class="z">I put my book down on the floor next to the bed, and lay on my back. Perhaps, had I shut my eyes now, nothing would have happened. But there I was, lying staring at the ceiling and listening to the ticking of the clock in the hallway.</div><div class="z">And a speck of sunlight jumped into the room through the glass. Small - the size of my hand - but surprisingly bright. As though the window was open, with bright summer sun outside. Someone was probably playing with a mirror on the balcony of the house across the street.</div><div class="z">The rabbit floated across the ceiling, climbed down a wall, made a vase on the dressing-table glint, and stopped, shaking slightly, on my headrest.</div><div class="z">- Don't go, - I said for some reason, knowing that in a moment the mirror would shift and the rabbit would leave my room forever. - Stay...</div><div class="z">And that's when it all started.</div><div class="z">The sun rabbit tore free of the bed and floated in the air. I didn't even realise at first that such things don't happen. It was only when the flat spot hanging in the air started puffing out to form a fuzzy orange ball that I understood - a miracle had happened.</div><div class="z">Four paws stretched from orange glowing fur, followed by a tail and a head. Green cat eyes blinked and gazed at me steadily. And overall, in fact, the rabbit looked more like a kitten than anything else. Except he was hanging in the air, glowing, and seemed light as the fairy fluff that floats away if one blows gently.</div><div class="z">- Hello, - purred the kitten. - Thank you for the invitation.</div><div class="z">I closed my eyes for a second, but when I opened them again, the kitten hadn't disappeared. In fact, he'd flown closer.</div><div class="z">- I don't believe in fairy tales, - I told myself. - I'm grown up now.</div><div class="z">- Well, compared to the girl who was holding the True Mirror, you are quite grown up, - declared the kitten, unperturbed, and lowered himself onto the blanket. I glanced over - to see if there would be smoke - but everything seemed all right. I could feel warmth with my chest, but not strong. And the kitten tilted his head and added: - But one can't really call you adult, either. How old are you? Ten, maybe?</div><div class="z">- Fourteen, - I replied, finding myself calming down at such a mundane question. - Who're you?</div><div class="z">- A sun rabbit, - replied the kitten, examining himself curiously. - What an appearance.. do I look like one?</div><div class="z">- <b>Like</b> what?</div><div class="z">- Like a <p style="font-weight:bold;color:red;">sun</p> rabbit.</div><div class="z">- More like a kitten.</div><div class="z">- Hardly better, - stated the Kitten sadly and stretched out. And I didn't think of anything better than repeating:</div><div class="z">- Who're you?</div><div class="z">- But we have already arrived at a consensus! - said the Kitten with sudden hurt. - A sun rabbit, or more precisely - a kitten, because I look far more like one! What is there not to understand?</div><div class="z">I found myself tongue-tied. Well, naturally, a small green animal that eats stones would simply be - a small green stone-eater. Simple. And a sun rabbit is a sun kitten, because he looks nothing like a rabbit.</div><div class="z">- So you mean - any rabbit can come to life if one just calls it? - I asked cautiously. For some reason it seemed to me the Kitten would be hurt at the question again. But he just shook his head proudly:</div><div class="z">- As if! Any! Only True Light, reflected in a True Mirror, can come to life.</div></div><div id="pagingControls"></div>
</div>
<script type="text/javascript">
var pager = new Imtech.Pager();
$(document).ready(function() {pager.paragraphsPerPage = 5; // set amount elements per pagepager.pagingContainer = $('#content'); // set of main containerpager.paragraphs = $('div.z', pager.pagingContainer); // set of required containerspager.showPage(1);
});
</script>

As you see – we put all content inside <div id="content"> element into P paragraphs. And than, using jQuery – doing small initialization of our pagination into prepared <div id="pagingControls"></div> element. Inside our initialization js script – you can see that I set our container element, name of paragraph tag, and amount paragraphs per page (5). All easy.

如您所见–我们将<div id =“ content”>元素内的所有内容放入P段落中。 然后,使用jQuery –对已准备好的<div id =“ pagingControls”> </ div>元素进行分页小初始化。 在初始化js脚本中–您可以看到我设置了我们的容器元素,段落标签的名称以及每页的段落数(5)。 一切都容易。

Update! I changed tag for paragraphs <p> to <div class="z"> for better selections. Now it able to handle with inline styles and tags

更新! 我将段落<p>的标记更改为<div class =“ z”>,以获得更好的选择。 现在它可以处理内联样式和标签

步骤2. CSS (Step 2. CSS)

Here are used CSS file. Just few styles for our demo:

这是用过CSS文件。 我们的演示仅提供几种样式:

css / styles.css (css/styles.css)


body{background:#eee;font-family:Verdana, Helvetica, Arial, sans-serif;margin:0;padding:0}
.example{background:#FFF;width:1000px;font-size:80%;border:1px #000 solid;margin:0.5em 10% 0.5em;padding:1em 2em 2em;-moz-border-radius:3px;-webkit-border-radius:3px}
#content p{text-indent:20px;text-align:justify;}
#pagingControls ul{display:inline;padding-left:0.5em}
#pagingControls li{display:inline;padding:0 0.5em}

body{background:#eee;font-family:Verdana, Helvetica, Arial, sans-serif;margin:0;padding:0}
.example{background:#FFF;width:1000px;font-size:80%;border:1px #000 solid;margin:0.5em 10% 0.5em;padding:1em 2em 2em;-moz-border-radius:3px;-webkit-border-radius:3px}
#content p{text-indent:20px;text-align:justify;}
#pagingControls ul{display:inline;padding-left:0.5em}
#pagingControls li{display:inline;padding:0 0.5em}

步骤3. JS (Step 3. JS)

Here are two JS files:

这是两个JS文件:

js / jquery.min.js (js/jquery.min.js)

Both – just jQuery library. Available in package.

两者-只是jQuery库。 封装形式。

js / imtech_pager.js(由于一些更正而更新) (js/imtech_pager.js (updated due few corrections))


var Imtech = {};
Imtech.Pager = function() {this.paragraphsPerPage = 3;this.currentPage = 1;this.pagingControlsContainer = '#pagingControls';this.pagingContainerPath = '#content';this.numPages = function() {var numPages = 0;if (this.paragraphs != null && this.paragraphsPerPage != null) {numPages = Math.ceil(this.paragraphs.length / this.paragraphsPerPage);}return numPages;};this.showPage = function(page) {this.currentPage = page;var html = '';this.paragraphs.slice((page-1) * this.paragraphsPerPage,((page-1)*this.paragraphsPerPage) + this.paragraphsPerPage).each(function() {html += '<div>' + $(this).html() + '</div>';});$(this.pagingContainerPath).html(html);renderControls(this.pagingControlsContainer, this.currentPage, this.numPages());}var renderControls = function(container, currentPage, numPages) {var pagingControls = 'Page: <ul>';for (var i = 1; i <= numPages; i++) {if (i != currentPage) {pagingControls += '<li><a href="#" onclick="pager.showPage(' + i + '); return false;">' + i + '</a></li>';} else {pagingControls += '<li>' + i + '</li>';}}pagingControls += '</ul>';$(container).html(pagingControls);}
}

var Imtech = {};
Imtech.Pager = function() {this.paragraphsPerPage = 3;this.currentPage = 1;this.pagingControlsContainer = '#pagingControls';this.pagingContainerPath = '#content';this.numPages = function() {var numPages = 0;if (this.paragraphs != null && this.paragraphsPerPage != null) {numPages = Math.ceil(this.paragraphs.length / this.paragraphsPerPage);}return numPages;};this.showPage = function(page) {this.currentPage = page;var html = '';this.paragraphs.slice((page-1) * this.paragraphsPerPage,((page-1)*this.paragraphsPerPage) + this.paragraphsPerPage).each(function() {html += '<div>' + $(this).html() + '</div>';});$(this.pagingContainerPath).html(html);renderControls(this.pagingControlsContainer, this.currentPage, this.numPages());}var renderControls = function(container, currentPage, numPages) {var pagingControls = 'Page: <ul>';for (var i = 1; i <= numPages; i++) {if (i != currentPage) {pagingControls += '<li><a href="#" onclick="pager.showPage(' + i + '); return false;">' + i + '</a></li>';} else {pagingControls += '<li>' + i + '</li>';}}pagingControls += '</ul>';$(container).html(pagingControls);}
}

现场演示

结论 (Conclusion)

I hope that today’s sample was pretty easy. And it will useful for your projects. Do not forget to say thank you :) Good luck!

我希望今天的样本很简单。 这将对您的项目有用。 别忘了说谢谢:)祝你好运!

翻译自: https://www.script-tutorials.com/how-to-create-easy-pagination-with-jquery/

jquery前端简单分页

jquery前端简单分页_如何使用jQuery创建简单的分页相关推荐

  1. jquery项目源码_第一个jQuery程序

    1.配置jQuery环境 1.1获取jQuery最新版本 进入jQuery的官方网址 http://jquery.com ,下载最新的jQuery库. 1.2 jQuery库类型说明 目前jQuery ...

  2. jquery 查找祖先元素_如何获得jQuery中元素的第一个祖先

    jquery 查找祖先元素 In this post, we will discuss about the traversal method to get the first ancestor of ...

  3. jquery 获取同级元素_如何在jQuery中获取元素的同级

    jquery 获取同级元素 In this post, we will discuss how to get the siblings of an HTML element in jQuery. jQ ...

  4. excel箱形图中位数_在Excel中创建简单的箱形图

    excel箱形图中位数 A box plot (box and whisker chart) lets you show how numbers are distributed in a set of ...

  5. django1.11 mysql配置_使用Django1.11创建简单的资产管理平台

    使用Django1.11创建简单的资产管理平台 发布时间:2020-06-05 00:06:17 来源:51CTO 阅读:883 作者:运维小学生 1:首先创建一个django项目[root@loca ...

  6. jsp创建mysql数据库_使用 MySQL 数据库创建简单的 JSP 应用程序(1)

    使用 MySQL 数据库创建简单的 Web 应用程序 编写人:Troy Giunipero 本文档描述了如何创建用于连接 MySQL 数据库服务器的简单 Web 应用程序.还讲述了 Web 开发中的一 ...

  7. jquery li ul 伪分页_求教关于Jquery的ul li的分页,该怎么处理

    求教关于Jquery的ul li的分页 ul 下有若干个li 3个为1个分页 1个input按钮点击显示后3个 另一个显示前3个 求大神这个怎么做 分享到: 更多 ------解决方案-------- ...

  8. jquery滚动条滚动事件_滚动条和jQuery –使用航点的事件处理

    jquery滚动条滚动事件 How to handle scrolling with jQuery. Today we continue jQuery reviews, and our article ...

  9. jquery关闭当前页面_什么是jQuery插件

    jquery插件就是一些人用jquery写的一些工具,我们在调用时只需要用很少的代码就能实现很好的效果,编写jquery插件的目的主要是给已经有的一系列方法或函数做一个封装,以便在其他地方重复使用,方 ...

最新文章

  1. Gradle学习之基础篇
  2. java 同步方式 lock_java的两种同步方式, Synchronized与ReentrantLock的区别
  3. 【项目总结】达能益力--官网
  4. 二级菜单打开一个时其他关闭_blender2.8教程 顶部菜单栏
  5. 使用IDEA创建一个Maven Web工程:无法创建Java Class文件
  6. arm linux系统启动流程
  7. 超级计算机比赛规则,AlphaGo是什么如何运行?人机大战比赛规则+交手记录资料...
  8. 零基础能掌握seo知识吗
  9. 127.0.0.1 zxt.php_php单文件版在线代码编辑器使用方法
  10. JavaScript 基本面试问题总结
  11. 剑指政企数智办公市场,通信厂商融云有何看家本领?
  12. AT32F435/437的如何选择选择代码启动地址
  13. 阿里P9李运华:架构到底是指什么?
  14. 网站优化十大方法之关键字篇
  15. 网易2018校招内推笔试-彩色砖块
  16. Contiki 系统框架
  17. 19C环境ORA-01035登陆报错处理
  18. 2022中国人力资源管理年度观察
  19. 广州百田2015校园招聘笔试题
  20. 虚拟机centos7安装python_Win10家庭版通过Hyper-V安装Centos7+Python3.7过程总结

热门文章

  1. 在Ubuntu 18.04上用源码安装GVM 20.08
  2. Teamview免费版连接超限解决办法
  3. sql server 导入excel数据表
  4. PDCP 功能与基本概念
  5. SVN 第一次上传项目和问题的解决方法
  6. vim ctrl + s 终端假死?
  7. 网络类型 ---- PAP认证配置 ---- CHAP认证----隧道技术
  8. 关于小米路由器的局域网内相互ping设备IP的解决方法
  9. Docker部署Jenkins服务
  10. echarts+vue中国地图,点击进入省级地图