js文章分页

可以设定每页的字数

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>文章分页</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<style>
* {
    font-size: 10.2pt;
    font-family: tahoma;
    line-height: 150%;
}

.divContent {
    width: 770px;
    word-break: break-all;
    margin: 10px 0px 10px;
    padding: 10px;
}
</style>
</head>
<body>


    <div id="divContent"></div>
    <div id="divPagenation"></div>
    <div id="Content" style="display: none;">
    请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦请问瑞哦亲为儿童与i哦亲为儿童与i哦
    </div>
    <SCRIPT LANGUAGE="JavaScript">
function DHTMLpagenation(content) {
    // 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()
{
    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()
{
    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()
{
    DHTMLpagenation.goto(currentPage-1);
};
DHTMLpagenation.next=function()
{
    DHTMLpagenation.goto(currentPage+1);
};
DHTMLpagenation.goto=function(iCurrentPage)
{
    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()
{
    divDisplayContent.innerHTML=strDisplayContent;
};
DHTMLpagenation.change=function(iPerpageLength)
{
    if(regularExp.test(iPerpageLength))
    {
        DHTMLpagenation.perpageLength=iPerpageLength;
        DHTMLpagenation.currentPage=1;
        DHTMLpagenation.initialize();
    }
    else
    {
        alert("请输入数字");
    }
};
DHTMLpagenation(document.getElementById('Content').innerHTML,200);
</SCRIPT>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值