利用JScript对长篇文章进行分页

来源:互联网 发布:周末去哪儿 知乎 编辑:程序博客网 时间:2024/04/26 07:05

<table width="99%" border="0" align="right" cellpadding="0" cellspacing="0">
 <tr>
        <td height="25" align="right" bgcolor="#E5FDDF">发布时间:<%=rs("fbdate")%>&nbsp;&nbsp;字体选择:【<a href="javascript:doZoom(16)" style="text-decoration: none;color:#000000">大</a>】【<a href="javascript:doZoom(14)" style="text-decoration: none;color:#000000">中</a>】【<a href="javascript:doZoom(12)" style="text-decoration: none;color:#000000">小</a>】【<a href="javascript:;" onClick="javascript:window.print()" style="text-decoration: none;color:#000000">打印】</a>&nbsp;&nbsp;来源:<%=rs("source")%>&nbsp;&nbsp;作者:<%=rs("author")%>&nbsp;&nbsp;</td>
</tr> 
 <tr>
 <td id="zoom"></td>
 </tr>
  <tr>
  <td height="25" id="page"></td>
  </tr>
  </table>

<%
   dim content:content=rs("content")
   set re=new RegExp
   re.IgnoreCase=true  
     re.Global=True  
     re.Pattern="/<.*?>|<.*?>(.*?)<//.*?>|<.*?>/g"            
     content=re.Replace(content,"")
   content=rePlace(rePlace(rePlace(rs("content").Value,"""","&#34;"),"'","&#39;"),vbCrlf,"<br />") '这里搞死我了
%>

<SCRIPT LANGUAGE="JavaScript">
<!--
var content="<%=content%>"
function Perpage(content) { with (this)
{

 this.content=content;
 this.contentLength=content.length;
 this.pageSizeCount;
 this.perpageLength=null;
 this.currentPage=1;
 this.regularExp=//d+/;

 this.S_content;
 this.contentStyle=null;
 this.scontent="";
 this.content_id;
 this.page_id="";
 
 arguments.length==2?perpageLength=arguments[1]:'';
 content_id=document.getElementById("page");
 S_content=document.getElementById("zoom");
 Perpage.initialize();
}};
Perpage.initialize=function() { with (this)
{
 S_content.className=contentStyle!=null?contentStyle:"zoom";
 if(contentLength<=perpageLength)
 {
  scontent=content;
  S_content.innerHTML=scontent;
  return null;
 }
 pageSizeCount=Math.ceil((contentLength/perpageLength));
 Perpage.goto(currentPage);
 Perpage.displayContent();
}};
Perpage.displayPage=function() { with (this)
{
    page_id="";
 if(currentPage&&currentPage!=1)
  page_id+='<a href="javascript:void(0)" onclick="Perpage.previous()">上一页</a>&nbsp;&nbsp;';
 else
  page_id+="上一页&nbsp;&nbsp;";

 for(var i=1;i<=pageSizeCount;i++)
 {
  if(i!=currentPage)
   page_id+='<a href="javascript:void(0)" onclick="Perpage.goto('+i+');">'+i+'</a>&nbsp;&nbsp;';
  else
   page_id+='<font color="#FF6600"><b>'+i+'</b></font>'+"&nbsp;&nbsp;";
 }

 if(currentPage&&currentPage!=pageSizeCount)
  page_id+='<a href="javascript:void(0)" onclick="Perpage.next()">下一页</a>&nbsp;&nbsp;';
 else
  page_id+="下一页&nbsp;&nbsp;";

 page_id+="共 " + pageSizeCount + " 页";

 content_id.innerHTML=page_id;
}};
Perpage.previous=function() { with(this)
{
 Perpage.goto(currentPage-1);
}};
Perpage.next=function() { with(this)
{
 Perpage.goto(currentPage+1);
}};
Perpage.goto=function(iCurrentPage) { with (this)
{
 startime=new Date();
 if(regularExp.test(iCurrentPage))
 {
  currentPage=iCurrentPage;
  scontent=content.substr((currentPage-1)*perpageLength,perpageLength);
 }
 else
 {
  alert("page parameter error!");
 }
 Perpage.displayPage();
 Perpage.displayContent();
}};
Perpage.displayContent=function() { with (this)
{
 S_content.innerHTML=scontent;
}};
function doZoom(size){
 document.getElementById('zoom').style.fontSize=size+'px' 
}
Perpage(content,1100);  //content为要显示的内容,1100为每页显示的字符串长度
//-->
</SCRIPT>

 
原创粉丝点击