`

7种JS脚本分页代码

    博客分类:
  • js
阅读更多

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="Copyright" content="懒人图库 http://www.makewing.com/" />
<meta name="description" content="学会偷懒,并懒出境界是提高工作效率最有效的方法!" />
<meta content="懒人图库" name="keywords" />
<title>懒人图库</title>
<style>
body {font-size: 18px;}

/* Pages Main Tyle */
.pages {
 color: #000000;
 cursor: default;
 font-size: 10px;
 font-family: Tahoma, Verdana;
 padding: 3px 0px 3px 0px;
}
.pages .count, .pages .number, .pages .arrow {
 color: #000000;
 font-size: 10px;
 background-color: #F7F7F7;
 border: 1px solid #CCCCCC;
}
/* Page and PageCount Style */
.pages .count {
 font-weight: bold;
 border-right: none;
 padding: 2px 10px 1px 10px;
}
/* Mode 0,1,2 Style (Number) */
.pages .number {
 font-weight: normal;
 padding: 2px 10px 1px 10px;
}
.pages .number a, .pages .number span {
 font-size: 14px;
}
.pages .number span {
 color: #999999;
 margin: 0px 3px 0px 3px;
}
.pages .number a {
 color: #000000;
 text-decoration: none;
}
.pages .number a:hover {
 color: #0000ff;
}
/* Mode 3 Style (Arrow) */
.pages .arrow {
 font-weight: normal;
 padding: 0px 5px 0px 5px;
}
.pages .arrow a, .pages .arrow span {
 font-size: 10px;
 font-family: Webdings;
}
.pages .arrow span {
 color: #999999;
 margin: 0px 5px 0px 5px;
}
.pages .arrow a {
 color: #000000;
 text-decoration: none;
}
.pages .arrow a:hover {
 color: #0000ff;
}
/* Mode 4 Style (Select) */
.pages select, .pages input {
 color: #000000;
 font-size: 10px;
 font-family: Tahoma, Verdana;
}
/* Mode 5 Style (Input) */
.pages .input input.ititle, .pages .input input.itext, .pages .input input.icount {
 color: #666666;
 font-weight: bold;
 background-color: #F7F7F7;
 border: 1px solid #CCCCCC;
}
.pages .input input.ititle {
 width: 70px;
 text-align: right;
 border-right: none;
}
.pages .input input.itext {
 width: 25px;
 color: #000000;
 text-align: right;
 border-left: none;
 border-right: none;
}
.pages .input input.icount {
 width: 35px;
 text-align: left;
 border-left: none;
}
.pages .input input.ibutton {
 height: 17px;
 color: #FFFFFF;
 font-weight: bold;
 font-family: Verdana;
 background-color: #999999;
 border: 1px solid #666666;
 padding: 0px 0px 2px 1px;
 margin-left: 2px;
 cursor: hand;
}
</style>
<script language="JavaScript" type="text/javascript">
<!--
/*

showPages v1.1
=================================

Infomation
----------------------
Author : Lapuasi
E-Mail : lapuasi@gmail.com
Web : http://www.lapuasi.com
Date : 2005-11-17


Example
----------------------
var pg = new showPages('pg');
pg.pageCount = 12; //定义总页数(必要)
pg.argName = 'p';    //定义参数名(可选,缺省为page)
pg.printHtml();        //显示页数


Supported in Internet Explorer, Mozilla Firefox
*/

function showPages(name) { //初始化属性
 this.name = name;      //对象名称
 this.page = 1;         //当前页数
 this.pageCount = 1;    //总页数
 this.argName = 'page'; //参数名
 this.showTimes = 1;    //打印次数
}

showPages.prototype.getPage = function(){ //丛url获得当前页数,如果变量重复只获取最后一个
 var args = location.search;
 var reg = new RegExp('[\?&]?' + this.argName + '=([^&]*)[&$]?', 'gi');
 var chk = args.match(reg);
 this.page = RegExp.$1;
}
showPages.prototype.checkPages = function(){ //进行当前页数和总页数的验证
 if (isNaN(parseInt(this.page))) this.page = 1;
 if (isNaN(parseInt(this.pageCount))) this.pageCount = 1;
 if (this.page < 1) this.page = 1;
 if (this.pageCount < 1) this.pageCount = 1;
 if (this.page > this.pageCount) this.page = this.pageCount;
 this.page = parseInt(this.page);
 this.pageCount = parseInt(this.pageCount);
}
showPages.prototype.createHtml = function(mode){ //生成html代码
 var strHtml = '', prevPage = this.page - 1, nextPage = this.page + 1;
 if (mode == '' || typeof(mode) == 'undefined') mode = 0;
 switch (mode) {
  case 0 : //模式1 (页数,首页,前页,后页,尾页)
   strHtml += '<span class="count">Pages: ' + this.page + ' / ' + this.pageCount + '</span>';
   strHtml += '<span class="number">';
   if (prevPage < 1) {
    strHtml += '<span title="First Page">&#171;</span>';
    strHtml += '<span title="Prev Page">&#139;</span>';
   } else {
    strHtml += '<span title="First Page"><a href="javascript:' + this.name + '.toPage(1);">&#171;</a></span>';
    strHtml += '<span title="Prev Page"><a href="javascript:' + this.name + '.toPage(' + prevPage + ');">&#139;</a></span>';
   }
   for (var i = 1; i <= this.pageCount; i++) {
    if (i > 0) {
     if (i == this.page) {
      strHtml += '<span title="Page ' + i + '">[' + i + ']</span>';
     } else {
      strHtml += '<span title="Page ' + i + '"><a href="javascript:' + this.name + '.toPage(' + i + ');">[' + i + ']</a></span>';
     }
    }
   }
   if (nextPage > this.pageCount) {
    strHtml += '<span title="Next Page">&#155;</span>';
    strHtml += '<span title="Last Page">&#187;</span>';
   } else {
    strHtml += '<span title="Next Page"><a href="javascript:' + this.name + '.toPage(' + nextPage + ');">&#155;</a></span>';
    strHtml += '<span title="Last Page"><a href="javascript:' + this.name + '.toPage(' + this.pageCount + ');">&#187;</a></span>';
   }
   strHtml += '</span><br />';
   break;
  case 1 : //模式1 (10页缩略,首页,前页,后页,尾页)
   strHtml += '<span class="count">Pages: ' + this.page + ' / ' + this.pageCount + '</span>';
   strHtml += '<span class="number">';
   if (prevPage < 1) {
    strHtml += '<span title="First Page">&#171;</span>';
    strHtml += '<span title="Prev Page">&#139;</span>';
   } else {
    strHtml += '<span title="First Page"><a href="javascript:' + this.name + '.toPage(1);">&#171;</a></span>';
    strHtml += '<span title="Prev Page"><a href="javascript:' + this.name + '.toPage(' + prevPage + ');">&#139;</a></span>';
   }
   if (this.page % 10 ==0) {
    var startPage = this.page - 9;
   } else {
    var startPage = this.page - this.page % 10 + 1;
   }
   if (startPage > 10) strHtml += '<span title="Prev 10 Pages"><a href="javascript:' + this.name + '.toPage(' + (startPage - 1) + ');">...</a></span>';
   for (var i = startPage; i < startPage + 10; i++) {
    if (i > this.pageCount) break;
    if (i == this.page) {
     strHtml += '<span title="Page ' + i + '">[' + i + ']</span>';
    } else {
     strHtml += '<span title="Page ' + i + '"><a href="javascript:' + this.name + '.toPage(' + i + ');">[' + i + ']</a></span>';
    }
   }
   if (this.pageCount >= startPage + 10) strHtml += '<span title="Next 10 Pages"><a href="javascript:' + this.name + '.toPage(' + (startPage + 10) + ');">...</a></span>';
   if (nextPage > this.pageCount) {
    strHtml += '<span title="Next Page">&#155;</span>';
    strHtml += '<span title="Last Page">&#187;</span>';
   } else {
    strHtml += '<span title="Next Page"><a href="javascript:' + this.name + '.toPage(' + nextPage + ');">&#155;</a></span>';
    strHtml += '<span title="Last Page"><a href="javascript:' + this.name + '.toPage(' + this.pageCount + ');">&#187;</a></span>';
   }
   strHtml += '</span><br />';
   break;
  case 2 : //模式2 (前后缩略,页数,首页,前页,后页,尾页)
   strHtml += '<span class="count">Pages: ' + this.page + ' / ' + this.pageCount + '</span>';
   strHtml += '<span class="number">';
   if (prevPage < 1) {
    strHtml += '<span title="First Page">&#171;</span>';
    strHtml += '<span title="Prev Page">&#139;</span>';
   } else {
    strHtml += '<span title="First Page"><a href="javascript:' + this.name + '.toPage(1);">&#171;</a></span>';
    strHtml += '<span title="Prev Page"><a href="javascript:' + this.name + '.toPage(' + prevPage + ');">&#139;</a></span>';
   }
   if (this.page != 1) strHtml += '<span title="Page 1"><a href="javascript:' + this.name + '.toPage(1);">[1]</a></span>';
   if (this.page >= 5) strHtml += '<span>...</span>';
   if (this.pageCount > this.page + 2) {
    var endPage = this.page + 2;
   } else {
    var endPage = this.pageCount;
   }
   for (var i = this.page - 2; i <= endPage; i++) {
    if (i > 0) {
     if (i == this.page) {
      strHtml += '<span title="Page ' + i + '">[' + i + ']</span>';
     } else {
      if (i != 1 && i != this.pageCount) {
       strHtml += '<span title="Page ' + i + '"><a href="javascript:' + this.name + '.toPage(' + i + ');">[' + i + ']</a></span>';
      }
     }
    }
   }
   if (this.page + 3 < this.pageCount) strHtml += '<span>...</span>';
   if (this.page != this.pageCount) strHtml += '<span title="Page ' + this.pageCount + '"><a href="javascript:' + this.name + '.toPage(' + this.pageCount + ');">[' + this.pageCount + ']</a></span>';
   if (nextPage > this.pageCount) {
    strHtml += '<span title="Next Page">&#155;</span>';
    strHtml += '<span title="Last Page">&#187;</span>';
   } else {
    strHtml += '<span title="Next Page"><a href="javascript:' + this.name + '.toPage(' + nextPage + ');">&#155;</a></span>';
    strHtml += '<span title="Last Page"><a href="javascript:' + this.name + '.toPage(' + this.pageCount + ');">&#187;</a></span>';
   }
   strHtml += '</span><br />';
   break;
  case 3 : //模式3 (箭头样式,首页,前页,后页,尾页) (only IE)
   strHtml += '<span class="count">Pages: ' + this.page + ' / ' + this.pageCount + '</span>';
   strHtml += '<span class="arrow">';
   if (prevPage < 1) {
    strHtml += '<span title="First Page">9</span>';
    strHtml += '<span title="Prev Page">7</span>';
   } else {
    strHtml += '<span title="First Page"><a href="javascript:' + this.name + '.toPage(1);">9</a></span>';
    strHtml += '<span title="Prev Page"><a href="javascript:' + this.name + '.toPage(' + prevPage + ');">7</a></span>';
   }
   if (nextPage > this.pageCount) {
    strHtml += '<span title="Next Page">8</span>';
    strHtml += '<span title="Last Page">:</span>';
   } else {
    strHtml += '<span title="Next Page"><a href="javascript:' + this.name + '.toPage(' + nextPage + ');">8</a></span>';
    strHtml += '<span title="Last Page"><a href="javascript:' + this.name + '.toPage(' + this.pageCount + ');">:</a></span>';
   }
   strHtml += '</span><br />';
   break;
  case 4 : //模式4 (下拉框)
   if (this.pageCount < 1) {
    strHtml += '<select name="toPage" disabled>';
    strHtml += '<option value="0">No Pages</option>';
   } else {
    var chkSelect;
    strHtml += '<select name="toPage" onchange="' + this.name + '.toPage(this);">';
    for (var i = 1; i <= this.pageCount; i++) {
     if (this.page == i) chkSelect=' selected="selected"';
     else chkSelect='';
     strHtml += '<option value="' + i + '"' + chkSelect + '>Pages: ' + i + ' / ' + this.pageCount + '</option>';
    }
   }
   strHtml += '</select>';
   break;
  case 5 : //模式5 (输入框)
   strHtml += '<span class="input">';
   if (this.pageCount < 1) {
    strHtml += '<input type="text" name="toPage" value="No Pages" class="itext" disabled="disabled">';
    strHtml += '<input type="button" name="go" value="GO" class="ibutton" disabled="disabled"></option>';
   } else {
    strHtml += '<input type="text" value="Input Page:" class="ititle" readonly="readonly">';
    strHtml += '<input type="text" id="pageInput' + this.showTimes + '" value="' + this.page + '" class="itext" title="Input page" onkeypress="return ' + this.name + '.formatInputPage(event);" onfocus="this.select()">';
    strHtml += '<input type="text" value=" / ' + this.pageCount + '" class="icount" readonly="readonly">';
    strHtml += '<input type="button" name="go" value="GO" class="ibutton" onclick="' + this.name + '.toPage(document.getElementById(\'pageInput' + this.showTimes + '\').value);"></option>';
   }
   strHtml += '</span>';
   break;
  default :
   strHtml = 'Javascript showPage Error: not find mode ' + mode;
   break;
 }
 return strHtml;
}
showPages.prototype.createUrl = function (page) { //生成页面跳转url
 if (isNaN(parseInt(page))) page = 1;
 if (page < 1) page = 1;
 if (page > this.pageCount) page = this.pageCount;
 var url = location.protocol + '//' + location.host + location.pathname;
 var args = location.search;
 var reg = new RegExp('([\?&]?)' + this.argName + '=[^&]*[&$]?', 'gi');
 args = args.replace(reg,'$1');
 if (args == '' || args == null) {
  args += '?' + this.argName + '=' + page;
 } else if (args.substr(args.length - 1,1) == '?' || args.substr(args.length - 1,1) == '&') {
   args += this.argName + '=' + page;
 } else {
   args += '&' + this.argName + '=' + page;
 }
 return url + args;
}
showPages.prototype.toPage = function(page){ //页面跳转
 var turnTo = 1;
 if (typeof(page) == 'object') {
  turnTo = page.options[page.selectedIndex].value;
 } else {
  turnTo = page;
 }
 self.location.href = this.createUrl(turnTo);
}
showPages.prototype.printHtml = function(mode){ //显示html代码
 this.getPage();
 this.checkPages();
 this.showTimes += 1;
 document.write('<div id="pages_' + this.name + '_' + this.showTimes + '" class="pages"></div>');
 document.getElementById('pages_' + this.name + '_' + this.showTimes).innerHTML = this.createHtml(mode);
 
}
showPages.prototype.formatInputPage = function(e){ //限定输入页数格式
 var ie = navigator.appName=="Microsoft Internet Explorer"?true:false;
 if(!ie) var key = e.which;
 else var key = event.keyCode;
 if (key == 8 || key == 46 || (key >= 48 && key <= 57)) return true;
 return false;
}
//-->
</script>
</head>

<body>
<p>
  <script language="JavaScript">
<!--
var pg = new showPages('pg');
pg.pageCount =14;  // 定义总页数(必要)
//pg.argName = 'p';  // 定义参数名(可选,默认为page)

document.write('<br>Show Times: ' + pg.showTimes + ', Mood Default');
pg.printHtml();
document.write('<br>Show Times: ' + pg.showTimes + ', Mood 0');
pg.printHtml(0);
document.write('<br>Show Times: ' + pg.showTimes + ', Mood 1');
pg.printHtml(1);
document.write('<br>Show Times: ' + pg.showTimes + ', Mood 2');
pg.printHtml(2);
document.write('<br>Show Times: ' + pg.showTimes + ', Mood 3 (only IE)');
pg.printHtml(3);
document.write('<br>Show Times: ' + pg.showTimes + ', Mood 4');
pg.printHtml(4);
document.write('<br>Show Times: ' + pg.showTimes + ', Mood 5');
pg.printHtml(5);
//-->
  </script>
</p>
<p>查找更多代码,请访问:<a href="http://www.lanrentuku.com" target="_blank">懒人图库</a></p>
</body>
</html>

  • 大小: 39.6 KB
分享到:
评论

相关推荐

    7种JS脚本分页代码showPages.pdf

    7种JS脚本分页代码showPages.pdf

    7种JS脚本分页代码 showPages v1.0.rar

    7种JS脚本分页代码 showPages v1.0

    JavaScript脚本分页代码

    JavaScript脚本实现分页功能,齐全的分页效果,简单实用

    js脚本分页代码分享(7种样式)

    本文跟大家分享了7种JS...7种JS脚本分页代码&lt;/title&gt; &lt;style&gt; body {font-size: 12px;} /* Pages Main Tyle */ .pages { color: #000000; cursor: default; font-size: 10px; font-family: Tahoma, Ver

    js分页,使用js脚本产生分页的html代码

    使用js脚本实现数据列表的分页,实现客户端分页功能

    js分页代码,分页代码

    用JS实现分页技术,可以对文本进行分页的,也不知道在那里下载到得,一直收藏的。现在贡献给CSDN里的同行。 放到body中就好了。

    Js 前台ajax 分页功能代码集.rar

    叶子JavaScript分页实例,JS分页代码,实现类似ajax分页的效果,无刷新实现分页功能,用JS模拟出了动态获取分页字符串进行无刷新分页的过程,里面的例子有7个,每一个都有不同的分页样式。请注意,此代码不包括后台...

    非要优秀的前端js 分页代码

    前端分页脚本,非常好用

    自己整理的一些网站常用JS效果1

    2.7种js脚本分页代码.html 3.CSS分页放大效果.html 4.CSS分页符代码.html 5.css制作翻页效果.html 6.div布局自由伸展.html 7.按照时间段提示消息.html 8.超酷带纹理网页滚动条效果.html 9.纯CSS代码实现翻页焦点图...

    精通JS脚本之ExtJS框架.part2.rar

     《精通JS脚本之ExtJS框架》附有配套光盘,提供了书中实例的源代码和视频教学文件。此外,读者还可以通过访问itzcn网站来获得即时在线帮助。  《精通JS脚本之ExtJS框架》可以作为Web开发的自学参考书,也可以作为...

    简单的js分页脚本

    js分页脚本实现代码。

    BI产品帆软FineReport真分页显示模板+JS分页脚本

    帆软分页显示的样例模板和分页脚本代码,适用于帆软报表开发人员,当使用帆软连接大数据量表进行显示时,可能会碰到页面刷新加载很慢的问题,通过此样例可以实现真分页的显示方式,大大的提高了页面刷新加载速度,...

    javascript原生脚本实现幻灯片效果

    原生的javascript脚本代码,实现幻灯片分页点击效果

    MvcPager分页示例MVC2.0源码

    5、支持Ajax分页模式下,若客户端浏览器不支持或禁用Javascript功能时安全降级为普通分页 6、搜索引擎友好,无论是普通分页还是Ajax分页,搜索引擎都可以直接搜索到所有页面。 7、支持ASP.NET MVC 1.0和最新的...

    jQuery.pager Js分页插件源代码与演示.rar

    jQuery.pager Js分页插件演示代码,使用了jQuery,也同时调用了jquery.pager.js文件,如果你不打算Ajax分页的话,那么你最好不要使用本插件,若使用的话反而很麻烦。本插件主要是为使用Ajax技术交互的网站所准备,...

    精通JS脚本之ExtJS框架.part1.rar

     《精通JS脚本之ExtJS框架》附有配套光盘,提供了书中实例的源代码和视频教学文件。此外,读者还可以通过访问itzcn网站来获得即时在线帮助。  《精通JS脚本之ExtJS框架》可以作为Web开发的自学参考书,也可以作为...

    使用AJAX实现自动分页效果

    使用AJAX实现自动分页效果,,结合Javascript脚本代码,,,

    数据库分页脚本 jsp

    &lt;script type="text/javascript"&gt; function gotoSelectedPage() { var x = document.getElementById("navigatorForm"); //alert("Original action: " + x.action) x.submit(); } &lt;/script&gt; ...

Global site tag (gtag.js) - Google Analytics