纯js分页代码(简洁实用)
纯js写的分页代码。
PageSize=5000;
//分页模式
flag=2;//1:根据字数自动分页 2:根据[NextPage]分页
//默认页
startpage = 1;
//导航显示样式 0:常规 1:直接 3:下拉
TopShowStyle = 1;
DownShowStyle = 0;
var currentSet,CutFlag,TotalByte,PageCount,key,tempText,tempPage;
key="";
currentSet=0;
var Text=xmlArticle.selectSingleNode("//Content").text;
TotalByte=Text.length;
if (flag==1)
{
PageCount=Math.round(TotalByte/PageSize);
if(parseFloat("0."+TotalByte%PageSize)>0){
if(parseFloat("0."+TotalByte%PageSize)<0.5){
PageCount=PageCount+1;
}
}
var PageNum=new Array(PageCount+1);
var PageTitle=new Array(PageCount+1);
PageNum[0]=0;
PageTitle[0]="";
var sDrv1,sDrv2,sDrv3,sDrv4,sFlag;
var sDrvL,sTemL;
var sTem1,sTem2,k;
sFlag=0;
for(j=1;j<PageCount+1;j++){
PageNum[j]=PageNum[j-1]+PageSize;
PageTitle[j]="";
//alert(j);
sDrv1="<br>";
sDrv2="<BR>";
sDrv3="<Br>";
sDrv4="<bR>";
sDrvL=sDrv1.length;
for(k=PageNum[j];k<=TotalByte;k++){
sTem1=Text.substring(PageNum[j]-sDrvL,k);
sTemL=sTem1.length;
sTem2=sTem1.substring(sTemL-sDrvL,sTemL)
if (sTem2==sDrv1 || sTem2==sDrv2 || sTem2==sDrv3 || sTem2==sDrv4)
{
sFlag=sFlag+1;
PageNum[j]=k;
break;
}
}
if (PageNum[j]>TotalByte)
{
break;
}
}
if (j<PageCount)
{
PageNum.length=j;
PageCount=j
}
if (PageCount>1&&sFlag>1&&PageCount<sFlag)
{
PageCount=sFlag+1;
}
}
else{
//手动分页
var j,sFlag,PageCount,sText;
var sTitleFlag;
var PageNum=new Array();
var PageTitle=new Array();
PageSize=0;
j=1;
PageNum[0]=-10;
PageTitle[0]="";
sFlag=0;
sText=Text;
do
{ www.jbxue.com
sText=Text.substring(PageNum[j-1]+10,TotalByte);
sFlag=sText.indexOf("[NextPage");
if (sText.substring(sFlag+9,sFlag+10)=="=")
{
sTitleFlag=sText.indexOf("]",sFlag);
PageTitle[j]=sText.substring(sFlag+10,sTitleFlag);
}
else{
PageTitle[j]="";
}
if (sFlag>0)
{
PageNum[j]=sFlag+PageNum[j-1]+10;
}
else{
PageNum[j]=TotalByte;
}
j+=1;
}
while (PageNum[j-1]<TotalByte);
PageCount=j-1;
}
function text_pagination(Page){
var Output,Byte;
if(Page==null){Page=1;}
Output="";
Output=Output+"<table width=100% height=30 border=0 align=center cellpadding=0 cellspacing=0>";
Output=Output+"<tr>";
Output=Output+"<td height=1 background=Images/DotLine.gif></td>";
Output=Output+"</tr>";
//头部功能导航条
Output=Output+"<tr>";
//正文查找
Output=Output+"<td align=left bgcolor=#f0faff width='40%'> ";
Output=Output+"<input type=text name=keys onchange='key=this.value' size=12> <input type=button name=search value='查找正文' onclick='searchkey();' style='width:60'>";
Output=Output+"</td>";
Output=Output+"<td align=right bgcolor=#f0faff>";
//页码显示方式一
//第x页:分页标题
if (Page==0 || PageCount==0){
Output=Output+"当前是:<font color=red>全文显示</font>" ;
}
else{
if(TotalByte>PageSize){Byte=PageNum[Page]-PageNum[Page-1]}else{Byte=TotalByte};
Output=Output+"第 <font color=red>"+Page+"</font> 页";
if (PageTitle[Page]!="")
{
Output=Output+":<font color=800000>"+PageTitle[Page]+"</font>";
}
Output+=' ';
}
//显示方式二
//下拉菜单选择
//if (PageCount>0)
//{
// Output=Output+Article_PageNav(2,Page);
// Output=Output+" </td>";
//}
//显示方式三
//页码选择列表
//Output=Output+"<td align=right bgcolor=#f0faff>";
//Output=Output+Article_PageNav(0,Page);
//Output=Output+"</td>";
Output=Output+"</tr>";
Output=Output+"<tr>";
Output=Output+"<td height=1 background=Images/DotLine.gif></td>";
Output=Output+"</tr>";
Output=Output+"</table>";
//显示正文
if(Page==0) {
//不分页
tempText=Text;
}
else{
//分页
if (flag==1)
//自动分页
{
tempText=Text.substring(PageNum[Page-1],PageNum[Page]);
}
else{
//手动分页
if (PageTitle[Page-1].length==0)
{
tempText=Text.substring(PageNum[Page-1]+10,PageNum[Page]);
}
else{ www.jbxue.com
tempText=Text.substring(PageNum[Page-1]+11+PageTitle[Page-1].length,PageNum[Page]);
}
}
}
//布置内容
Output=Output+"<div align=center>";
Output=Output+Article_PageNav(TopShowStyle,Page);
Output=Output+"</div>";
Output=Output+"<div id=world>";
Output=Output+tempText;
Output=Output+"</div>";
Output=Output+"<br>";
Output=Output+"<div align=center>";
Output=Output+Article_PageNav(DownShowStyle,Page);
Output=Output+"</div>";
article.innerHTML = Output;
if (Page>1)
{
document.location.href='#top';
}
eval(document.all.keys).value=key;
if (key!=""){searchkey();}
}
function searchkey(){
//正文查找函数
h="<font class=keyworld>";
f="</font>";
keyset=new Array();
key=document.all.keys.value;
if (key==""){
alert("请输入关键字!");
return;
}
else{
keyset[0]=tempText.indexOf(key,0);
if (keyset[0]<0){
return;
}else
temp=tempText.substring(0,keyset[0]);
temp=temp+h+key+f;
temp2=tempText.substring(keyset[0]+key.length,tempText.length);
for (i=1;i<tempText.length;i++) {
keyset[i]=tempText.indexOf(key,keyset[i-1]+key.length);
if(keyset[i]<0){
temp=temp+tempText.substring(keyset[i-1]+key.length,tempText.length);
break;
}else{
temp=temp+tempText.substring(keyset[i-1]+key.length,keyset[i])+h+key+f;
}
}
world.innerHTML = temp;
}
}
function Article_PageNav(ShowStyle,Page){
//分页码显示函数
//参数为调用样式,0=简单样式,1=标准样式
var temp="";
if (ShowStyle==0)
//简单样式
{
tempPage=Page;
if(TotalByte>PageSize){
if (Page-4<=1){
temp=temp+"<font face=webdings color=#999999>9</font>";
if (Page<=1){temp=temp+"<font face=webdings color=#999999>7</font>";}else{temp=temp+"<a href=javascript:text_pagination("+(Page-1)+")><font face=webdings>7</font></a>";}
if (PageCount>10){
for(i=1;i<8;i++){
if (i==Page){
temp=temp+"<font color=red>"+i+"</font> ";
}else{
temp=temp+"<a href=javascript:text_pagination("+i+") >"+i+"</a>"+" ";
}
}
temp=temp+" ...";
}
else{
for(i=1;i<PageCount+1;i++){
if (i==Page){
temp=temp+"<font color=red>"+i+"</font> ";
}
else{
temp=temp+"<a href=javascript:text_pagination("+i+") >"+i+"</a>"+" ";
}
}
}
if (Page==PageCount){temp=temp+"<font face=webdings color=#999999>8</font>";}else{temp=temp+"<a href=javascript:text_pagination("+(Page+1)+")><font face=webdings>8</font></a>";}
if(PageCount<10){temp=temp+"<font face=webdings color=#999999>:</font>";}else{temp=temp+"<a href=javascript:text_pagination("+PageCount+")><font face=webdings>:</font></a>";}
}
else if(Page+4<=PageCount){
temp=temp+"<a href=javascript:text_pagination(1)><font face=webdings>9</font></a>";
temp=temp+"<a href=javascript:text_pagination("+(Page-1)+")><font face=webdings>7</font></a>";
if (PageCount>10){
temp=temp+"..";
for(i=Page-4;i<Page+4;i++){
if (i==Page){
temp=temp+"<font color=red>"+i+"</font> ";
}
else{
temp=temp+"<a href=javascript:text_pagination("+i+") >"+i+"</a>"+" ";
}
}
temp=temp+" ..";
}
else{
for(i=1;i<PageCount+1;i++){
if (i==Page){
temp=temp+"<font color=red>"+i+"</font> ";
}
else{
temp=temp+"<a href=javascript:text_pagination("+i+") >"+i+"</a>"+" ";
}
}
}
if (Page==PageCount){temp=temp+"<font face=webdings color=#999999>8</font>";}else{temp=temp+"<a href=javascript:text_pagination("+(Page+1)+")><font face=webdings>8</font></a>";}
temp=temp+"<a href=javascript:text_pagination("+PageCount+")><font face=webdings>:</font></a>";
}
else{ www.jbxue.com
temp=temp+"<a href=javascript:text_pagination(1)><font face=webdings>9</font></a>";
temp=temp+"<a href=javascript:text_pagination("+(Page-1)+")><font face=webdings>7</font></a>";
temp=temp+".."
for(i=Page-2;i<PageCount+1;i++){
if (i==Page){
temp=temp+"<font color=red>"+i+"</font> ";
}
else{
temp=temp+"<a href=javascript:text_pagination("+i+") >"+i+"</a>"+" ";
}
}
if (Page==PageCount){temp=temp+"<font face=webdings color=#999999>8</font>";}else{temp=temp+"<a href=javascript:text_pagination("+(Page+1)+")><font face=webdings>8</font></a>";}
temp=temp+"<font face=webdings color=#999999>:</font>";
}
}
else{
temp=temp+"<font color=red>1</font> ";
}
temp=temp+" <a href=javascript:text_pagination(0)>显示全部</a>"
}
else if (ShowStyle==1)
//标准样式
{
if(TotalByte>PageSize){if(Page!=0){if(Page!=1){temp=temp+"<a href='#top' onclick=javascript:text_pagination("+(Page-1)+")><font color=3366cc>[上一页]</font></a> ";}}}
for (i=1;i<PageCount+1 ;i++ )
{
if (Page==i)
{
temp=temp+"<font color=800000>["+i+"]</font> ";
}
else{
temp=temp+"<a href='#top' onclick=javascript:text_pagination("+i+")><font color=3366cc>["+i+"]</font></a> ";
}
}
temp=temp+"<a name='foot'></a>";
if(TotalByte>PageSize){if(Page!=0){if(Page!=PageCount){temp=temp+"<a href='#top' onclick=javascript:text_pagination("+(Page+1)+")><font color=3366cc>[下一页]</font></a>";}}}
temp=temp+" <a href=javascript:text_pagination(0)><font color=3366cc>显示全部</font></a>"
}
else if (ShowStyle==2)
//下拉菜单样式
{
temp=temp+'<select onchange="text_pagination(this.value)">'
for (i=1;i<PageCount+1 ;i++ )
{
if (Page==i)
{
temp=temp+"<option value='"+i+"' selected style='color:red'>第 "+i+" 页"
}
else{
temp=temp+"<option value='"+i+"'>第 "+i+" 页";
}
if (PageTitle[i].length!=0)
{
temp=temp+':'+PageTitle[i];
}
temp=temp+"</option>";
}
temp=temp+"</select>";
}
return (temp);
}
//默认页
text_pagination(startpage);
--------------分页js代码结束--------------
------------html页面,调用分页js------------------
<META http-equiv=Content-Type content="text/html; charset=gb2312">
</HEAD>
<BODY bottomMargin=0 leftMargin=0 topMargin=0 rightMargin=0>
<TABLE cellSpacing=1 cellPadding=5 width="95%" align=center
border=0>
<TBODY>
<TR>
<TD>
<xml id=xmlArticle>
<Article>
<Info>
<Content>
<![CDATA[
大家来试验分页哦~~~~~[NextPage]我分~~~[NextPage]我再分[NextPage]分分分
]]>
</Content>
</Info>
</Article>
</xml>
<!--正文分页Js-->
<SCRIPT language=Javascript
src="attachments/month_0607/j200674214834.js"></SCRIPT>
</TD></TD></TR></TBODY></TABLE></TD></TR>
</TBODY></TABLE>
纯js分页代码(简洁实用)的更多相关文章
- jQuery+AJAX实现纯js分页功能
使用jQuery的AJAX技术,在bootstrap的框架下搭建的纯js分页 bootstrap作为Twitter推的一款前端框架,效果个人还是觉得很不错的.这次只是拿来作为网页元素的css样式表使用 ...
- angular.js分页代码的实例
对于大多数web应用来说显示项目列表是一种很常见的任务.通常情况下,我们的数据会比较多,无法很好地显示在单个页面中.在这种情况下,我们需要把数据以页的方式来展示,同时带有转到上一页和下一页的功能.现在 ...
- js分页代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xh ...
- Angular.js分页代码
$scope.reloadList=function(){ $scope.findPage( $scope.pagina ...
- 纯js实现分页
原理:所有数据已加载好,js通过遍历部分显示,实现分页效果 html代码 <html> <head> <meta charset='utf-8'> <scri ...
- 纯js手动分页
昨天让做个页面,后台提供所有数据,没有做好分页,需要前端js手动分页. 我参考了 http://www.cnblogs.com/jiechn/p/4095029.html 做了些许改动让分页效果更加完 ...
- 非常不错的一个JS分页效果代码
这里分享一个不错的js分页代码. 代码中cpage是页面计数,应为全局变量,可以随处调用它: totalpage是总页数. 与asp分页代码很类似,也是先取得记录总数,然后实现分页,基本的分页思路与原 ...
- kPagination纯js实现分页插件
kPagination分页插件 纯js分页插件,压缩版本~4kb,样式可以自定义 demo 使用方法 <div id="pagination"></div> ...
- js分页demo
纯js实现分页 原理:所有数据已加载好,js通过遍历部分显示,实现分页效果 html代码 <html> <head> <meta charset='utf-8'> ...
随机推荐
- Java Hashtable类
哈希表(Hashtable)是原来的java.util中的一部分,是一个字典的具体实现. 然而,Java2重新设计的哈希表,以便它也实现了Map接口.因此,哈希表现已集成到集合框架.它类似于Has ...
- 【Android 界面效果30】Android中ImageSwitcher结合Gallery展示SD卡中的资源图片
本文主要是写关于ImageSwitcher结合Gallery组件如何展示SDCard中的资源图片,相信大家都看过API Demo 中也有关于这个例子的,但API Demo 中的例子是展示工程中Draw ...
- (一)u-boot2013.01.01 for TQ210:《Uboot简介》
一直想写一个s5pv210硬件平台的u-boot的移植文档,但一直都忙着没时间写.先写一些u-boot的脚本分析吧,包括makefile,mkconfig,config.mk,主要侧重于语法句意的分析 ...
- java开发常用命令
cd /d e:work2,更改至当前工作目录svnup.bat,批量更新所有项目 @echo off for /D %%i in (.\*) do ( echo %%i svn up %%i )ho ...
- C++构造/析构/赋值函数
在编写C++程序的时候,我们会为特定某一类对象申明类类型,几乎我们申明的每一个class都会有一个或多个构造函数.一个析构函数.一个赋值运算符重载=.以及拷贝构造函数.这些函数控制着类对象的基础操作, ...
- 正则转nfa:完成
太累了,感觉不会再爱了.问题已经解决,具体的懒得说了. #include "regular_preprocess.h" //这个版本终于要上nfa了,好兴奋啊 //由于连个节点之间 ...
- poj 1191 矩形块的划分
思路:黑书的例题 #include<iostream> #include<cstring> #include<algorithm> #include<cmat ...
- CF 118E Bertown roads 桥
118E Bertown roads 题目:把无向图指定边的方向,使得原图变成有向图,问能否任意两点之间互达 分析:显然如果没有桥的话,存在满足题意的方案.输出答案时任意从一个点出发遍历一遍即可. 求 ...
- Wordpress 运行缓慢的解决方法
原因为wordpress 3.8之后采用google字体所致. 修改 functions.php //禁用Open Sans class Disable_Google_Fonts { pub ...
- 【转】c语言入门教程 / c语言入门经典书籍
用C语言开始编写代码 初级:C语言入门必备 (以下两本书任选一本即可) C语言是作为从事实际编程工作的程序员的一种工具而出现的,本阶段的学习最主要的目的就是尽快掌握如何用c语言编写程序的技能.对c语言 ...