蔡林

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
<title>动态html分页</title>&lt;style&gt;
* {
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;
}
&lt;/style&gt;
header
<div id="divContent"></div>
<div id="divPagenation"></div>

<div id="divContentTest" style="display: none;">文章正文</div>
&lt;script language="JavaScript"&gt;
&lt;!--
s= document.getElementById("divContentTest").innerHTML;
function DHTMLpagenation(content) { with (this)
{
	// client static html file pagenation

	this.content=content;
	this.contentLength=content.length;
	this.pageSizeCount;
	this.perpageLength=400; //default perpage byte length.
	this.currentPage=1;
	//this.regularExp=/.+[\?\&amp;]{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&lt;=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&amp;&amp;currentPage!=1)
		strDisplayPagenation+='&lt;a href="javascript:void(0)" onclick="DHTMLpagenation.previous()"&gt;上一页&lt;/a&gt;&amp;nbsp;&amp;nbsp;';
	else
		strDisplayPagenation+="上一页&amp;nbsp;&amp;nbsp;";

	for(var i=1;i&lt;=pageSizeCount;i++)
	{
		if(i!=currentPage)
			strDisplayPagenation+='&lt;a href="javascript:void(0)" onclick="DHTMLpagenation.goto('+i+');"&gt;'+i+'&lt;/a&gt;&amp;nbsp;&amp;nbsp;';
		else
			strDisplayPagenation+=i+"&amp;nbsp;&amp;nbsp;";
	}

	if(currentPage&amp;&amp;currentPage!=pageSizeCount)
		strDisplayPagenation+='&lt;a href="javascript:void(0)" onclick="DHTMLpagenation.next()"&gt;下一页&lt;/a&gt;&amp;nbsp;&amp;nbsp;';
	else
		strDisplayPagenation+="下一页&amp;nbsp;&amp;nbsp;";

	strDisplayPagenation+="共 " + pageSizeCount + " 页每页" + perpageLength + " 字符,调整字符数:&lt;input type='text' value='"+perpageLength+"' id='ctlPerpageLength'&gt;&lt;input type='button' value='确定' onclick='DHTMLpagenation.change(document.getElementById(\"ctlPerpageLength\").value);'&gt;";

	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.displayContent();
	DHTMLpagenation.displayPage();
}};
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,300);

//--&gt;
&lt;/script&gt;

 





已有 0 人发表留言,猛击->>这里<<-参与讨论


JavaEye推荐



posted on 2010-10-13 10:13  蔡林  阅读(1956)  评论(0编辑  收藏  举报