<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="pageModel.doFirst();" >首页</a>
<a href="#" onclick="pageModel.doUp();" >上一页</a>
<a href="#" onclick="pageModel.doNext();" >下一页</a>
<a href="#" onclick="pageModel.doLast();" >尾页</a>
<input id="goPage" style="width:20px"/><a href="#" onclick="pageModel.doGo();" >GO</a>
<!--
有时候,页面打开后,source里没有元素内容,是因为当前的页面仍处于编辑状态,未保存,保存后,会正常显示
-->
</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);
} this.doFirst=function (){ //首页
pageModel.cunPage=1;
contentDiv.innerHTML=doShow(pageModel.cunPage,stus);
} this.doUp=function (){ //上一页
if(pageModel.cunPage<=1){
return ;
}
pageModel.cunPage--;
contentDiv.innerHTML=doShow(pageModel.cunPage,stus);
} this.doNext=function (){ //下一页
if(pageModel.cunPage>=pageModel.totalPage()){
return ;
}
pageModel.cunPage++;
contentDiv.innerHTML=doShow(pageModel.cunPage,stus);
} this.doLast=function (){ //最后一页
pageModel.cunPage=pageModel.totalPage();
contentDiv.innerHTML=doShow(pageModel.cunPage,stus);
} this.doGo=function (){ //跳转
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;
pageModel.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="pageModel.doFirst();" >首页</a>
<a href="#" onclick="pageModel.doUp();" >上一页</a>
<a href="#" onclick="pageModel.doNext();" >下一页</a>
<a href="#" onclick="pageModel.doLast();" >尾页</a>
<input id="goPage" style="width:20px"/><a href="#" onclick="pageModel.doGo();" >GO</a>
<!--
有时候,页面打开后,source里没有元素内容,是因为当前的页面仍处于编辑状态,未保存,保存后,会正常显示
-->
</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);
} this.doFirst=function (){ //首页
pageModel.cunPage=1;
contentDiv.innerHTML=doShow(pageModel.cunPage,stus);
} this.doUp=function (){ //上一页
if(pageModel.cunPage<=1){
return ;
}
pageModel.cunPage--;
contentDiv.innerHTML=doShow(pageModel.cunPage,stus);
} this.doNext=function (){ //下一页
if(pageModel.cunPage>=pageModel.totalPage()){
return ;
}
pageModel.cunPage++;
contentDiv.innerHTML=doShow(pageModel.cunPage,stus);
} this.doLast=function (){ //最后一页
pageModel.cunPage=pageModel.totalPage();
contentDiv.innerHTML=doShow(pageModel.cunPage,stus);
} this.doGo=function (){ //跳转
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;
pageModel.doFirst();
</script>
</html>

最新文章

  1. win7 装了VB虚拟机 开始挺好用 后来突然就打不开了 提示如下错误:(如图)创建 COM 对象失败.
  2. NYOJ题目97兄弟郊游问题
  3. 使用方法:mail_sendmail($params)
  4. Mono.Posix.dll文件
  5. mysql中count(),group by使用
  6. 二模 (8) day1
  7. 分享10款功能强大的HTML5/CSS3应用插件
  8. 如何把匿名类型.GetType()返回的对象传进泛型里面[转]
  9. js正则语法
  10. hdu 4553 约会安排
  11. HTTP/2 简介
  12. SpringCloud学习系列之二 ----- 服务消费者(Feign)和负载均衡(Ribbon)使用详解
  13. mssql sqlserver 使用sql脚本输出交替不同的背景色的html信息的方法分享
  14. python2x 和 python 3x的区别
  15. java.lang.IllegalStateException: Failed to check the status of the service
  16. Android Retrofit2 数据解析
  17. drupal7 带表达式条件的update
  18. java环境和Tomcat环境
  19. 20170928-3 四则运算psp
  20. sphinx配置 + php

热门文章

  1. Linux下汇编语言学习笔记46 ---
  2. 【VBA研究】工作表自己主动筛选模式检測
  3. Office 针式打印机如何调节边距
  4. Linux下C编程的学习_1
  5. react-native redux 操作
  6. poj3211Washing Clothes(字符串处理+01背包) hdu1171Big Event in HDU(01背包)
  7. Swift—使用try?和try!区别-仅供参考
  8. Cocos2d-x 脚本语言Lua基本数据结构-表(table)
  9. TCP从连接到释放过程全解
  10. 数据分析-excel基础篇