使用JS分页 <span> beta 2.0 未封装的分页
<html>
<head>
<title>分页</title>
<style>
#titleDiv{
width:500px;
background-color:silver;
margin-left:300px;
/***/margin-top:100px;
}
#titleDiv span{
margin-left:50px;
} #contentDiv{
width:500px;
background-color:gray;
margin-left:300px; }
#contentDiv span{
/**display:inline;
width:100px;*/
margin-left:50px;
}
#pageDiv{
width:500px;
margin-left:420px;
margin-top:20px;
/**background-color:gold;*/
} #pageDiv span{
margin-left:10px;
}
</style>
</head>
<body>
<div id="titleDiv">
<span>学号</span><span>姓名</span><span>年龄</span><span>性别</span><br/>
</div> <div id="contentDiv"> </div> <div id="pageDiv">
<!--<span onclick="doFirst();">首页</span><span onclick="doUp();">上一页</span>
<span onclick="doNext();">下一页</span><span onclick="doLast();">尾页</span>
<input id="goPage" style="width:20px"/><span onclick="doGo();">GO</span> <!--
<input type="button" onclick="doFirst();" value="首页"></input><input type="button" onclick="doUp();" value="上一页"></input>
<input type="button" onclick="doNext();" value="下一页"></input><input type="button" onclick="doLast();" value="尾页"></input>
<input id="goPage" style="width:20px"/><input type="button" onclick="doGo();" value="GO"></input>
</div>
-->
<a href="#" onclick="doFirst();" >首页</a>
<a href="#" onclick="doUp();" >上一页</a>
<a href="#" onclick="doNext();" >下一页</a>
<a href="#" onclick="doLast();" >尾页</a>
<input id="goPage" style="width:20px"/><a href="#" onclick="doGo();" >GO</a>
</body>
<script>
var stus=[];
function Student(num,sname,age,sex){
this.num=num;
this.sname=sname;
this.age=age;
this.sex=sex;
this.toString=function(){
return num+"-"+sname+"-"+age+"-"+sex;
}
}
//初始化
function init(){
//多个学生信息装入数组中
for(var i=0;i<55;i++){
stus.push(new Student(10000+i,'zs'+i,20+i,'男'));
}
}
</script> <script>
var contentDiv=document.getElementById("contentDiv");
/**
数据源 显示位置 每页显示几个 当前页
可以把下面方法 封装到分页模型,实现通用性 如果是table,如何实现分页功能?
*/
//分页模型
function PageModel(){
this.cunPage;//当前页
this.pageContent;//一页显示多少个
this.totalNum;//总记录数
this.totalPage=function (){
return Math.ceil(this.totalNum/this.pageContent);
} } //首页
function doFirst(){
pageModel.cunPage=1;
contentDiv.innerHTML=doShow(pageModel.cunPage,stus);
} //上一页
function doUp(){
if(pageModel.cunPage<=1){
return ;
}
pageModel.cunPage--;
contentDiv.innerHTML=doShow(pageModel.cunPage,stus);
} //下一页
function doNext(){
if(pageModel.cunPage>=pageModel.totalPage()){
return ;
}
pageModel.cunPage++;
contentDiv.innerHTML=doShow(pageModel.cunPage,stus);
} //最后一页
function doLast(){
pageModel.cunPage=pageModel.totalPage();
contentDiv.innerHTML=doShow(pageModel.cunPage,stus);
} //跳转
function doGo(){
var goPage =parseInt(document.getElementById("goPage").value);
if(goPage<1||goPage>pageModel.totalPage()){
return ;
}
pageModel.cunPage=parseInt(goPage);
contentDiv.innerHTML=doShow(pageModel.cunPage,stus);
} //插入显示
function doShow(CurrentPage,stus){
var start=(CurrentPage-1)*pageModel.pageContent;
var end=CurrentPage*pageModel.pageContent;
var s="";
for(var i=start;i<end;i++){
if(stus[i]!=null){
s+='<span>'+stus[i].num+'</span><span>'+stus[i].sname+'</span><span>'
+stus[i].age+'</span><span>'+stus[i].sex+'</span><br/>';
}
}
return s;
}
</script>
<script>
init();
var pageModel=new PageModel();
pageModel.pageContent=10;
pageModel.totalNum=stus.length;
doFirst();
</script>
</html>
<html>
<head>
<title>分页</title>
<style>
#titleDiv{
width:500px;
background-color:silver;
margin-left:300px;
/***/margin-top:100px;
}
#titleDiv span{
margin-left:50px;
} #contentDiv{
width:500px;
background-color:gray;
margin-left:300px; }
#contentDiv span{
/**display:inline;
width:100px;*/
margin-left:50px;
}
#pageDiv{
width:500px;
margin-left:420px;
margin-top:20px;
/**background-color:gold;*/
} #pageDiv span{
margin-left:10px;
}
</style>
</head>
<body>
<div id="titleDiv">
<span>学号</span><span>姓名</span><span>年龄</span><span>性别</span><br/>
</div> <div id="contentDiv"> </div> <div id="pageDiv">
<!--<span onclick="doFirst();">首页</span><span onclick="doUp();">上一页</span>
<span onclick="doNext();">下一页</span><span onclick="doLast();">尾页</span>
<input id="goPage" style="width:20px"/><span onclick="doGo();">GO</span> <!--
<input type="button" onclick="doFirst();" value="首页"></input><input type="button" onclick="doUp();" value="上一页"></input>
<input type="button" onclick="doNext();" value="下一页"></input><input type="button" onclick="doLast();" value="尾页"></input>
<input id="goPage" style="width:20px"/><input type="button" onclick="doGo();" value="GO"></input>
</div>
-->
<a href="#" onclick="doFirst();" >首页</a>
<a href="#" onclick="doUp();" >上一页</a>
<a href="#" onclick="doNext();" >下一页</a>
<a href="#" onclick="doLast();" >尾页</a>
<input id="goPage" style="width:20px"/><a href="#" onclick="doGo();" >GO</a>
</body>
<script>
var stus=[];
function Student(num,sname,age,sex){
this.num=num;
this.sname=sname;
this.age=age;
this.sex=sex;
this.toString=function(){
return num+"-"+sname+"-"+age+"-"+sex;
}
}
//初始化
function init(){
//多个学生信息装入数组中
for(var i=0;i<55;i++){
stus.push(new Student(10000+i,'zs'+i,20+i,'男'));
}
}
</script> <script>
var contentDiv=document.getElementById("contentDiv");
/**
数据源 显示位置 每页显示几个 当前页
可以把下面方法 封装到分页模型,实现通用性 如果是table,如何实现分页功能?
*/
//分页模型
function PageModel(){
this.cunPage;//当前页
this.pageContent;//一页显示多少个
this.totalNum;//总记录数
this.totalPage=function (){
return Math.ceil(this.totalNum/this.pageContent);
} } //首页
function doFirst(){
pageModel.cunPage=1;
contentDiv.innerHTML=doShow(pageModel.cunPage,stus);
} //上一页
function doUp(){
if(pageModel.cunPage<=1){
return ;
}
pageModel.cunPage--;
contentDiv.innerHTML=doShow(pageModel.cunPage,stus);
} //下一页
function doNext(){
if(pageModel.cunPage>=pageModel.totalPage()){
return ;
}
pageModel.cunPage++;
contentDiv.innerHTML=doShow(pageModel.cunPage,stus);
} //最后一页
function doLast(){
pageModel.cunPage=pageModel.totalPage();
contentDiv.innerHTML=doShow(pageModel.cunPage,stus);
} //跳转
function doGo(){
var goPage =parseInt(document.getElementById("goPage").value);
if(goPage<1||goPage>pageModel.totalPage()){
return ;
}
pageModel.cunPage=parseInt(goPage);
contentDiv.innerHTML=doShow(pageModel.cunPage,stus);
} //插入显示
function doShow(CurrentPage,stus){
var start=(CurrentPage-1)*pageModel.pageContent;
var end=CurrentPage*pageModel.pageContent;
var s="";
for(var i=start;i<end;i++){
if(stus[i]!=null){
s+='<span>'+stus[i].num+'</span><span>'+stus[i].sname+'</span><span>'
+stus[i].age+'</span><span>'+stus[i].sex+'</span><br/>';
}
}
return s;
}
</script>
<script>
init();
var pageModel=new PageModel();
pageModel.pageContent=10;
pageModel.totalNum=stus.length;
doFirst();
</script>
</html>
使用JS分页 <span> beta 2.0 未封装的分页的更多相关文章
- 使用JS分页 <span> beta 3.0 完成封装的分页
<html> <head> <title>分页</title> <style> #titleDiv{ width:500px; backgr ...
- 使用JS分页 <span> beta 1.0
<html> <head> <title>分页</title> <style> #titleDiv{ width:500px; backgr ...
- vue.js 2.0实现的简单分页
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title&g ...
- 抓取Js动态生成数据且以滚动页面方式分页的网页
代码也可以从我的开源项目HtmlExtractor中获取. 当我们在进行数据抓取的时候,如果目标网站是以Js的方式动态生成数据且以滚动页面的方式进行分页,那么我们该如何抓取呢? 如类似今日头条这样的网 ...
- 发布Ext JS 5.1 beta版本
原文:Announcing Ext JS 5.1 Beta 概述 我们很高兴的宣布,Ext JS 5.1 beta发布了.自从Ext JS 5.0.1,我们一直在努力添加一些令人兴奋的和一些在Senc ...
- 【JavaScript 封装库】BETA 5.0 测试版发布!
JavaScript 前端框架(封装库) BETA 5.0 已于10月10日正式发布,今天开始提供 BETA 5.0 的 API 参考文献.相较于之前 5 个版本的发布都是草草的提供源代码,并没有很多 ...
- 用Vue2.0实现简单的分页及跳转
用Vue2.0实现简单的分页及跳转 2018年07月26日 20:29:51 Freya_yyy 阅读数 3369 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog ...
- 【原创】自己动手写工具----XSmartNote [Beta 3.0]
一.前面的话 在动笔之前,一直很纠结到底要不要继续完成这个工具,因为上次给它码代码还是一年多之前的事情,参考自己动手写工具----XSmartNote [Beta 2.0],这篇博文里,很多园友提出了 ...
- EF Core 1.0 和 SQLServer 2008 分页的问题
EF Core 1.0 在sqlserver2008分页的时候需要指定用数字分页. EF Core1.0 生成的分页语句中使用了 Featch Next.这个语句只有在SqlServer2012的时候 ...
随机推荐
- [USACO08NOV]时间管理Time Management
题目描述 Ever the maturing businessman, Farmer John realizes that he must manage his time effectively. H ...
- 确定位置的经纬度LocationUtil
package com.pingyijinren.test; import android.content.Context; import android.location.Location; imp ...
- Codeforces 631D Messenger【KMP】
题意: 给定由字符串块(字符及连续出现的个数)组成的字符串t,s,求t串中有多少个s. 分析: KMP 这题唯一需要思考的地方就是如何处理字符串块.第一想到是把他们都展开然后进行KMP,可是展开后实在 ...
- 基于xml配置springmvc
controller关键代码 public class MenuController extends MultiActionController 方法: public ModelAndView lis ...
- Mysql入门实战中
前面一章主要解说了mysql的入门学习.包括数据库,表的管理,以及对数据的增删改,本章主要介绍mysql最重要的语句select的使用方法.将select的大部分使用方法进行分别解说. 全部代码下载( ...
- Linux system log avahi-daemon[3640]: Invalid query packet.
2014-06-11 Check the Linux system log find the errorr: Jun 9 11:18:49 hostname avahi-daemon[3640]: ...
- node-V8
Node是基于V8引擎的,所以我们运行Js文件不会存在问题,下面演示一下: 因为安装Vscode后,会自动添加本路径到path,所以可以用 code yes.js 来执行创建文件 Vscode是基于N ...
- Vue.js 组件的三个 API:prop、event、slot
组件的构成 一个再复杂的组件,都是由三部分组成的:prop.event.slot,它们构成了 Vue.js 组件的 API.如果你开发的是一个通用组件,那一定要事先设计好这三部分,因为组件一旦发布,后 ...
- Maven手工安装jar包到本地仓库
使用maven,少不了的就是要被"包下载失败"这种问题折腾. jar包下载失败后.我们选择手工把jar下载下来.(能够下载到指定jar的途经非常多) 以下随便找了一个jar包为例. ...
- 改动MyEclipse行数的颜色
改动MyEclipse行数的颜色 1.未改动前.行数的颜色 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveW91MjNoYWk0NQ==/font/5a6 ...