通过jq实现分页的原理如下:将所有条数加载到页面中,根据每页放特定条数(例如 5 条)获取jquery对象索引,使部分条数显示,其他条数隐藏。

前提:引入jquery.js

代码

<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
list-style: none;
}
.wrapper{
width: 800px;
margin: 50px auto;
}
/*清除浮动*/
.wrapper::after{
content: "";
display: block;
clear: both;
}
ul li{
width: 100%;
height: 30px;
text-align: center;
line-height: 30px;
float: left;
background: #ccc;
margin: 10px 0px;
}
a{
cursor: pointer;
border:1px solid black;
}
.btn{
float: right;
}
</style>
<script type="text/javascript" src="jquery-3.1.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
/*添加100条数据(模仿后台传入)*/
for(var i = 1; i<101;i++){
$("#content").append("<li>"+i+"</li>");
}
/*设置每页显示的条数*/
$every_page = 5; $items = $("ul li");
$total_all = $items.length;//总条数
$page_num = Math.round($total_all/$every_page)//向上取整(2.5 ==> 3) $("#total_page").text($page_num);
//初始化页面,只显示前5条。
$("ul li:gt("+($every_page-1)+")").each(function(){
$(this).hide();
})
//点击下一条按钮函数。
$("#next_page").click(function(){
$current_page = ($("#current_page").text());//获取当前页码
if($current_page <$page_num){
$("#current_page").text(++$current_page);
$.each($("ul li"),function(index,item){
//获取下一页显示的开始索引。
var start = ($("#current_page").text()-1)*$every_page;
if(index>=start&& index<start+$every_page){
$(this).show();
}else{
$(this).hide();
}
})
}else{
return false;
}
})
$("#pre_page").click(function(){
$current_page = ($("#current_page").text());
if($current_page > 1){
$("#current_page").text(--$current_page);
$.each($("ul li"),function(index,item){
var start = ($("#current_page").text()-1)*$every_page;
if(index>=start&& index<start+$every_page){
$(this).show();
}else{
$(this).hide();
}
})
}else{
return false;
}
})
})
</script>
</head>
<body>
<div class="wrapper">
<div class="items">
<ul id= "content"> </ul>
</div>
<span class="btn">
<a id = "pre_page">上一页</a>
<span>
<span id = "current_page">1</span>
<span>/</span>
<span id = "total_page"></span>
</span>
<a id = "next_page">下一页</a>
</span>
</div>
</body>
</html>

运行结果

jquery实现分页效果的更多相关文章

  1. 使用Jquery做分页效果

    之前写过一个PHP 的分页效果,但是今天小伙伴和我说了一个不适用后台单纯用前段的JS来写分页,整理了一下,代码如下: html: <div id="containet"> ...

  2. jQuery伪分页效果

    如图,我们首先分析在一个页面存放4条内容,其余的超出隐藏(因为这里没有后台数据,所以我们把内容‘写死’),然后就是下面两个按钮(这里我们不用button,因为button有自带的提交功能),然后我们可 ...

  3. SpringMVC -jquery实现分页

    效果图: 关键类的代码: package:utils: SpringUtil.java 通过jdbcTemplate连接oracle数据库 package com.utils; import org. ...

  4. jquery动态分页

    最近一直研究jquery的分页效果,刚刚弄好了一个,拿出来与大家分享.分页效果与时光网的差不多. 网址:http://www.mtime.com/movie/news/all/ 先在aspx页面放置一 ...

  5. JS实现分页效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. 分享5种风格的 jQuery 分页效果【附代码】

    jPaginate 是一款非常精致的分页插件,提供了五种不同风格的分页效果,支持鼠标悬停翻页,快速分页功能.这款插件还提供了丰富的配置选项,你可以根据需要进行设置. 效果演示      源码下载 各个 ...

  7. 5种风格的 jQuery 分页效果【附代码】

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  8. 基于jquery 的分页插件,前端实现假分页效果

    上次分享了一款jquery插件,现在依旧分享这个插件,不过上一次分享主要是用于regular框件,且每一页数据都是从后端获取过来的,这一次的分享主要是讲一次性获取完数据 然后手动进行分页.此需求基本上 ...

  9. 使用jQuery Pagination Plugin实现分页效果

    最近使用分页这个基础效果较为频繁,而项目前端页面使用的是纯静态的HTML,自己之前写的JSP中的分页就用不成了:项目中也引入了Bootstrap,本来想使用Bootstrap中的分页样式,但发现其样式 ...

随机推荐

  1. Mac 安装RN android开发环境

    前言 前面介绍了MAC 安装,再来讲讲mac 安装 安卓的开发环境 首先貌似很多Mac自带安卓JDK ,你可以在终端上输入java -version 看是否已经有java开发环境. 如果没有java开 ...

  2. 一例tornado框架下利用python panda对数据进行crud操作

    get提交部分 <script> /* $("#postbtn").click(function () { $.ajax({ url:'/loaddata', data ...

  3. js 设置多条css样式

    如果在一个网页中给id="mydiv"的元素添加css样式,先获取该节点:var obj = document.getElementById("mydiv"); ...

  4. SQL Server自动备份

    1.打开SQL Server Management Studio 数据库-管理-维护计划,右键,维护计划向导 2.在弹出页面右下方点击[更改],修改计划执行方案 根据需要,修改执行时间 3.修改完毕后 ...

  5. [转] Siamese network 孪生神经网络--一个简单神奇的结构

    转自: 作者:fighting41love 链接:https://www.jianshu.com/p/92d7f6eaacf5 1.名字的由来 Siamese和Chinese有点像.Siam是古时候泰 ...

  6. Java多线程和并发(十二),Java线程池

    目录 1.利用Executors创建线程的五种不同方式 2.为什么要使用线程池 3.Executor的框架 4.J.U.C的三个Executor接口 5.ThreadPoolExecutor 6.线程 ...

  7. JS框架_(coolShow.js)图片旋转动画特效

    百度云盘 传送门 密码:ble6 coolShow.js插件图片旋转动画效果 <!DOCTYPE HTML> <head> <meta http-equiv=" ...

  8. DVWA--Brute Force

    这次我们尝试的内容是DVWA的暴力破解 --lower 先抓取一个登陆的包 然后发送到后在Position选项中设置需要破解的变量.Burpsuite会自动设置许多变量,单击“Clear”按钮,把默认 ...

  9. java 判断Map集合中包含指定的键名,则返回true,否则返回false。

    public static void main(String[] args) { Map map = new HashMap(); //定义Map对象 map.put("apple" ...

  10. ShiroFilterFactoryBean 找不到的原因

    是因为参考的那篇shiro的博客,没有引入这个依赖的原因 <dependency> <groupId>org.apache.shiro</groupId> < ...