长文章javascript分页(多浏览器兼容修正版)
来源:互联网 发布:小区业主号码采集软件 编辑:程序博客网 时间:2024/04/30 17:02
先废话两句:
网上流传的这个js分页原版有如下2个Bug:
1.把"上一页 下一页"钮换成图片点击超链接 <a href="#"><img src="图片文件"></a> 后不能弹到页首(这个我也没解决)
2.在 firefox 和 opera 里标签divContent不显示.
在 firefox里不兼容是因为 firefox 不支持 this 关键字(我试的时候是这样的,有不同意见的网友希望能给我发email)
在opera 里不兼容是因为 程序中使用了 goto, opera 里视 goto 为关键字顾不显示
下面是修改过的代码:
<div id="divContent" name="divContent"></div>
<br>
<div id="divPagenation" name="divPagenation" style="font-size:12px;" align="center"></div>
<script>
s="文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容文章内容";
// 封装DHTMLpagenation
function DHTMLpagenation(content)
{
with (DHTMLpagenation)
{
// client static html file pagenation
// Scipit by blueDestiny,never-online, www.never-online.net
DHTMLpagenation.content=content; // 内容
DHTMLpagenation.contentLength=content.length; // 内容长度
DHTMLpagenation.pageSizeCount; // 总页数
DHTMLpagenation.perpageLength=100; //default perpage byte length.
DHTMLpagenation.currentPage=1; // 起始页为第1页
DHTMLpagenation.regularExp=//d+/; // 建立正则表达式,匹配数字型字符串。
DHTMLpagenation.divDisplayContent;
DHTMLpagenation.divDisplayPagenation;
DHTMLpagenation.contentStyle=null;
DHTMLpagenation.strDisplayContent="";
DHTMLpagenation.strDisplayPagenation="";
// 把第二个参数赋给perpageLength;
arguments.length==2?perpageLength=arguments[1]:'';
try
{
divExecuteTime=document.createElement("div");
document.body.appendChild(divExecuteTime);
}
catch(e)
{
}
// 得到divPagenation容器。
if(document.getElementById("divPagenation"))
{
divDisplayPagenation=document.getElementById("divPagenation");
}
else
{
try
{
divDisplayPagenation=document.createElement("div");
divDisplayPagenation.id="divPagenation";
document.body.appendChild(divDisplayPagenation);
}
catch(e)
{
return false;
}
}
// 得到divContent容器
if(document.getElementById("divContent"))
{
divDisplayContent=document.getElementById("divContent");
}
else
{
try
{
divDisplayContent=document.createElement("div");
divDisplayContent.id="divContent";
document.body.appendChild(divDisplayContent);
}
catch(e)
{
return false;
}
}
DHTMLpagenation.initialize();
return DHTMLpagenation;
}
};
//初始化分页;
//包括把加入CSS,检查是否需要分页
DHTMLpagenation.initialize=function()
{
with (DHTMLpagenation)
{
divDisplayContent.className=contentStyle!=null?contentStyle:"divContent";
if(contentLength<=perpageLength)
{
strDisplayContent=content;
divDisplayContent.innerHTML=strDisplayContent;
return null;
}
pageSizeCount=Math.ceil((contentLength/perpageLength));
DHTMLpagenation.gotopage(currentPage);
DHTMLpagenation.displayContent();
}
};
//显示分页栏
DHTMLpagenation.displayPage=function()
{
with (DHTMLpagenation)
{
var a = document.location.toString();
var b = a.lastIndexOf("/")+1;
var c = a.substr(b).split(".");
var url = c[0]+"."+ c[1];
//alert(url);
strDisplayPagenation="";
if(currentPage&¤tPage!=1)
strDisplayPagenation+='<a href="#" onclick="DHTMLpagenation.previous();">上一页</a> ';
else
strDisplayPagenation+=" ";
for(var i=1;i<=pageSizeCount;i++)
{
if(i!=currentPage)
strDisplayPagenation+='<a href="#" onclick="DHTMLpagenation.gotopage('+i+');">['+i+']</a> ';
else
strDisplayPagenation+=i+" ";
}
if(currentPage&¤tPage!=pageSizeCount)
{
strDisplayPagenation+='<a href="#" onclick="DHTMLpagenation.next();">下一页</a> ';
}
else
{
strDisplayPagenation+=" ";
//strDisplayPagenation+="共 " + pageSizeCount + " 页";
}
divDisplayPagenation.innerHTML=strDisplayPagenation;
}};
//上一页
DHTMLpagenation.previous=function() { with(DHTMLpagenation)
{
DHTMLpagenation.gotopage(currentPage-1);
}};
//下一页
DHTMLpagenation.next=function() { with(DHTMLpagenation)
{
DHTMLpagenation.gotopage(currentPage+1);
}};
//跳转至某一页
DHTMLpagenation.gotopage=function(iCurrentPage) { with (DHTMLpagenation)
{
startime=new Date();
if(regularExp.test(iCurrentPage))
{
currentPage=iCurrentPage;
strDisplayContent=content.substr((currentPage-1)*perpageLength,perpageLength);
}
else
{
alert("page parameter error!");
}
DHTMLpagenation.displayPage();
DHTMLpagenation.displayContent();
}};
//显示当前页内容
DHTMLpagenation.displayContent=function() { with (DHTMLpagenation)
{
divDisplayContent.innerHTML=strDisplayContent;
}};
//改变每页的字节数
DHTMLpagenation.change=function(iPerpageLength) { with(DHTMLpagenation)
{
if(regularExp.test(iPerpageLength))
{
DHTMLpagenation.perpageLength=iPerpageLength;
DHTMLpagenation.currentPage=1;
DHTMLpagenation.initialize();
}
else
{
alert("请输入数字");
}
}};
// 接口API
// DHTMLpagenation(strContent[,perpageLength])
DHTMLpagenation(s,800);
</script>
- 长文章javascript分页(多浏览器兼容修正版)
- 兼容多浏览器Javascript实现分页功能
- 非常简单的兼容多浏览器Javascript实现分页功能
- javascript &css实现的长文章分页
- Javascript多浏览器兼容
- JavaScript多浏览器兼容
- JavaScript多浏览器兼容
- Javascript 多浏览器 兼容
- 长遍文章分页C#版
- 长文章分页代码
- asp 长文章分页
- asp长文章分页
- 长文章分页
- php长文章分页
- 给长文章分页
- 长文章分页
- asp长文章分页
- asp长文章分页
- 转:把电视当显示器使用 通过S端子连接电脑技巧
- 朋友要结婚拉!
- SEO 服务前辈们纷纷改行
- oracle 闪回功能
- Hibernate入门
- 长文章javascript分页(多浏览器兼容修正版)
- 转:两台联网电脑,其中一台打不开另一台中的共享文件,如何解决?
- 技术是一种加速器 但重要的不是技术
- 关键词 排名 与 SEO
- Scroll Page 表单提交后页面重新滚回原来滚动条所在位置
- Spring的核心机制依赖注入简介
- Microsoft.XMLHttp的属性和方法的简介及使用
- Microsoft.XMLHttp的属性和方法的简介及使用
- oracle10G学习笔记(SQL开发指南)续