js 分頁

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<style>
* {
font-size:10.2pt;
font-family:tahoma;
line-height:150%;
}
.divContent
{
border:1px solid red;
background-color:#FFD2D3;
width:500px;
word-break:break-all;
margin:10px 0px 10px;
padding:10px;
}
</style>
</HEAD>
<BODY>
header
<div id="divPagenation"></div>
<div id="divContent"></div>
footer
<SCRIPT LANGUAGE="JavaScript">
<!--
s="<p>女老師竭力向孩子們證實,學習好功課的重要性。 </p><p>她說:&ldquo;牛頓坐在樹下,眼睛盯着樹在思考,這時,有一個蘋果落在他的頭上,因而他發現了萬有引力定律,孩子們,大家想一想看,作一位偉大的科學家多麼好,多麼神氣啊,要想作到這一點,就必須好好學習。&rdquo; </p><p>&ldquo;班上一個調皮鬼對此並不滿意。他說:&ldquo;興許是這樣,但是,假如他坐在學校裏,埋頭書本,那他就什麼也發現不了啦。&rdquo; </p><p>女老師竭力向孩子們證實,學習好功課的重要性。 </p><p>她說:&ldquo;牛頓坐在樹下,眼睛盯着樹在思考,這時,有一個蘋果落在他的頭上,因而他發現了萬有引力定律,孩子們,大家想一想看,作一位偉大的科學家多麼好,多麼神氣啊,要想作到這一點,就必須好好學習。&rdquo; </p><p>&ldquo;班上一個調皮鬼對此並不滿意。他說:&ldquo;興許是這樣,但是,假如他坐在學校裏,埋頭書本,那他就什麼也發現不了啦。&rdquo; </p><p>女老師竭力向孩子們證實,學習好功課的重要性。 </p><p>她說:&ldquo;牛頓坐在樹下,眼睛盯着樹在思考,這時,有一個蘋果落在他的頭上,因而他發現了萬有引力定律,孩子們,大家想一想看,作一位偉大的科學家多麼好,多麼神氣啊,要想作到這一點,就必須好好學習。&rdquo; </p><p>&ldquo;班上一個調皮鬼對此並不滿意。他說:&ldquo;興許是這樣,但是,假如他坐在學校裏,埋頭書本,那他就什麼也發現不了啦。&rdquo; </p><p>女老師竭力向孩子們證實,學習好功課的重要性。 </p><p>她說:&ldquo;牛頓坐在樹下,眼睛盯着樹在思考,這時,有一個蘋果落在他的頭上,因而他發現了萬有引力定律,孩子們,大家想一想看,作一位偉大的科學家多麼好,多麼神氣啊,要想作到這一點,就必須好好學習。&rdquo; </p><p>&ldquo;班上一個調皮鬼對此並不滿意。他說:&ldquo;興許是這樣,但是,假如他坐在學校裏,埋頭書本,那他就什麼也發現不了啦。&rdquo; </p><p>女老師竭力向孩子們證實,學習好功課的重要性。 </p><p>她說:&ldquo;牛頓坐在樹下,眼睛盯着樹在思考,這時,有一個蘋果落在他的頭上,因而他發現了萬有引力定律,孩子們,大家想一想看,作一位偉大的科學家多麼好,多麼神氣啊,要想作到這一點,就必須好好學習。&rdquo; </p><p>&ldquo;班上一個調皮鬼對此並不滿意。他說:&ldquo;興許是這樣,但是,假如他坐在學校裏,埋頭書本,那他就什麼也發現不了啦。&rdquo; </p>";
function DHTMLpagenation(content) { with (this)
{
// client static html file pagenation
this.content=content;
this.contentLength=content.length;
this.pageSizeCount;
this.perpageLength=100; //default perpage byte length.
this.currentPage=1;
//this.regularExp=/.+[\?\&]{1}page=(\d+)/;
this.regularExp=/\d+/;
this.divDisplayContent;
this.contentStyle=null;
this.strDisplayContent="";
this.divDisplayPagenation;
this.strDisplayPagenation="";
arguments.length==2?perpageLength=arguments[1]:'';
try {
divExecuteTime=document.createElement("DIV");
document.body.appendChild(divExecuteTime);
}
catch(e)
{
}
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;
}
}
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;
}
}
DHTMLpagenation.initialize();
return this;
}};
DHTMLpagenation.initialize=function() { with (this)
{
divDisplayContent.className=contentStyle!=null?contentStyle:"divContent";
if(contentLength<=perpageLength)
{
strDisplayContent=content;
divDisplayContent.innerHTML=strDisplayContent;
return null;
}
pageSizeCount=Math.ceil((contentLength/perpageLength));
DHTMLpagenation.goto(currentPage);
DHTMLpagenation.displayContent();
}};
DHTMLpagenation.displayPage=function() { with (this)
{
strDisplayPagenation="分頁:";
if(currentPage&&currentPage!=1)
strDisplayPagenation+='<a href="javascript:void(0)" onclick="DHTMLpagenation.previous()">上一頁</a>&nbsp;&nbsp;';
else
strDisplayPagenation+="上一頁&nbsp;&nbsp;";
for(var i=1;i<=pageSizeCount;i++)
{
if(i!=currentPage)
strDisplayPagenation+='<a href="javascript:void(0)" onclick="DHTMLpagenation.goto('+i+');">'+i+'</a>&nbsp;&nbsp;';
else
strDisplayPagenation+=i+"&nbsp;&nbsp;";
}
if(currentPage&&currentPage!=pageSizeCount)
strDisplayPagenation+='<a href="javascript:void(0)" onclick="DHTMLpagenation.next()">下一頁</a>&nbsp;&nbsp;';
else
strDisplayPagenation+="下一頁&nbsp;&nbsp;";
strDisplayPagenation+="共 " + pageSizeCount + " 頁,每頁" + perpageLength + " 字符,調整字符數:<input type='text' value='"+perpageLength+"' id='ctlPerpageLength'><input type='button' value='肯定' onclick='DHTMLpagenation.change(document.getElementById(\"ctlPerpageLength\").value);'>";
divDisplayPagenation.innerHTML=strDisplayPagenation;
}};
DHTMLpagenation.previous=function() { with(this)
{
DHTMLpagenation.goto(currentPage-1);
}};
DHTMLpagenation.next=function() { with(this)
{
DHTMLpagenation.goto(currentPage+1);
}};
DHTMLpagenation.goto=function(iCurrentPage) { with (this)
{
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 (this)
{
divDisplayContent.innerHTML=strDisplayContent;
}};
DHTMLpagenation.change=function(iPerpageLength) { with(this)
{
if(regularExp.test(iPerpageLength))
{
DHTMLpagenation.perpageLength=iPerpageLength;
DHTMLpagenation.currentPage=1;
DHTMLpagenation.initialize();
}
else
{
alert("請輸入數字");
}
}};
// method
// DHTMLpagenation(strContent,perpageLength)
DHTMLpagenation(s,100);
//-->
</SCRIPT>
</BODY>
</HTML>javascript

相關文章
相關標籤/搜索