page 分页
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<ul class="list"> </ul>
</body>
<script type="text/javascript">
/**
* 数量多(数据) 假设120条数据
* 一页N条
* 一共多少页 120/N
*
* 数量123条
* 每页15条
* 告诉我第6页 应该取几到几
*
* 花 123/15 等于9页
*
* 1-15 1
* 16-30 2
* 31-45 3
* 46-60 4
*
* 页码-1 * 每页数量 +1
*
* (3-1)*15+1 31 ~ 3*15
*
* 内容
* 每页的内容数量
*
* 一花多少条
* 每页(组) 显示多少条
* 一共有多少组 总条数/每组数量 = 总组数
* 根据页码取区间的数据 (当前页码-1)*每页数量+1 起始值 页码*每页数量 结束值
*
*
*
*
*
*/ function page(data,num){ this.data = data || []; this.num = num || 10; this.total = 0; this.prev = 0; this.next = 0; this.home = 1; this.end = 0; this.current = 1; this.pages; return this.init().getPage(); } page.prototype = { init:function(){ var data = this.data.length; var total = Math.ceil(data/this.num); this.end = total; this.total = total; return this
},
getPage:function(){ var url = location.search.substr(1).split('&'); var current = 0; for(var i = 0; i<url.length;i++){ var tmp = url[i].split('='); if(tmp[0]=='page'){ current = tmp[1]; } } current = parseInt(current) || 1; this.current = current; this.next = current<this.total ? current+1:this.end; this.prev = current>1 ? current-1 : 1; return this }, getContent:function(){ var cur = this.current; var num = this.num; var start = (cur-1)*num+1; var end = cur*num; var pageList = []; end = end< this.data.length ? end :this.data.length; for(;start<=end;start++){ pageList.push(start)
}
// 起始值 当前页-1*每页条数+1
// 结束值 当前页*每页条数 this.pages = pageList; return this
}, pageList:function(){ return this
} } var data = []; for(var i = 0; i<124;i++){ data.push('第'+(i+1)+'条内容')
} var demo = new page(data).getContent() console.log(demo) var html = ''; for(var i = 0; i<demo.pages.length;i++){ html+='<li><a href="xx.php?id='+demo.pages[i]+'">'+demo.pages[i]+data[demo.pages[i]-1]+'</a></li>'; } document.querySelector('.list').innerHTML = html; </script>
</html>
page 分页的更多相关文章
- page分页问题,根据页码获取对应页面的数据,接口调用
添加一个log.js文件,进行接口调用. import axios from '@/libs/api.request' const MODULE_URL = '/log'; export const ...
- layui -page 分页类
<?phpnamespace page; // +---------------------------------------------------------------------- / ...
- 封装page分页类
类: <?php //分页工具类 class Page{ /* * 获取分页字符串 * @param1 string $uri,分页要请求的脚本url ...
- page分页
首先封装一个分页类 public class Page<T> { /** * 当前页号 */ private int pageNumber; /** * 总条数 */ private in ...
- page分页类
<?php /** file: Page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 private $lis ...
- java Page分页显示
//entity层实体类 import java.util.List; //分页展示 //相关属性:当前页,页大小(每页显示的条数),总页数,总条数,数据 //select * from t_user ...
- jQuery.page 分页控件
分享一下自己在项目中引用的Jquery分页控件 index.html内容 <!DOCTYPE html> <html lang="zh-cn" xmlns=&qu ...
- MVC Page分页控件
MVCPage帮助类 控制器代码 public ActionResult Article(int? page) { //Session["ArticleClass"] = cont ...
- JPA+Postgresql+Spring Data Page分页失败
按照示例进行如下代码编写 Repository Page<DeviceEntity> findByTenantId(int tenantId, Pageable pageable); se ...
随机推荐
- spring boot: thymeleaf模板引擎使用
spring boot: thymeleaf模板引擎使用 在pom.xml加入thymeleaf模板依赖 <!-- 添加thymeleaf的依赖 --> <dependency> ...
- sgu 116 Index of super-prime
题意:用最少的super-prime组成n; 找出所有的super-prime数,只有202个.用完全背包记录能取到n值的最少数量.再找出7要哪些元素. #include <iostream&g ...
- IDEA设置类、方法注释模板
类注释模板 File -> Other Setting -> Default Setting打开默认设置 Editor -> File and Code Templates -> ...
- PHP函数总结 (二)
<?php header('content-type:text/html;charset=utf8');// 只要声明的函数在脚本中可见,就可以通过函数名在脚本的任何位置调用echo table ...
- php fpm深度解析
摘自:https://www.cnblogs.com/wanghetao/p/3934350.html 当我们在谈到cgi的时候,我们在讨论什么 最早的Web服务器简单地响应浏览器发来的HTTP请求, ...
- POJ-3744 Scout YYF I (矩阵优化概率DP)
题目大意:有n颗地雷分布在一条直线上,有个人的起始位置在1,他每次前进1步的概率为p,前进两步的概率为1-p,问他不碰到地雷的概率. 题目分析:定义状态dp(i)表示到了dp(i)的概率,则状态转移方 ...
- java使用HttpClient
HttpClient常用的包有两个 org.apache.http.client以及org.apache.commons.httpclient 我常用的是org.apache.http.client. ...
- XML Publisher Using API’s(转)
原文地址:XML Publisher Using API’s Applications Layer APIsThe applications layer of XML Publisher allows ...
- 30. Substring with Concatenation of All Words *HARD*
You are given a string, s, and a list of words, words, that are all of the same length. Find all sta ...
- 关于display:grid layout
.wrapper { display: grid; grid-template-columns: repeat(3, 1fr); grid-gap: 10px; grid-auto-rows: min ...