新闻内页-JS分页


Posted in Javascript onJune 07, 2006

'//判断内容里是不是包含这个分页标签
if instr(cinfo,"[NextPage]")>0 then
flag=1
else
flag=0
end if

'//设置参数
<script language="Javascript" >
var Text,PageSize,flag
Text="<%=DealJsText(cinfo)%>";
PageSize=1500;
flag=<%=flag%>;
</script>

'//JS文件包函
<script language="Javascript" src="CutArticle.js"></script>

'//文本显示
<span class="news">
<div id="article" style="font-size:12px;"></div>
<script language="JavaScript">
if (flag==1 || flag==2){
text_pagination(1);
}
else{
article.innerHTML=Text;
}
</script>
</span>

'//下面为JS文本处理函数

function DealJsText(Str)
if not isnull(Str) then
Dim re,po,ii
Str = Replace(Str, CHR(9), " ")
Str = Replace(Str, CHR(39), "'")
Str = Replace(Str, CHR(13), "")
Str = Replace(Str, CHR(10) & CHR(13), "</P><P> ")
Str = Replace(Str, CHR(10), "")
Str = Replace(Str, "‘", "'")
Str = Replace(Str, "'", "'")
Str = Replace(Str, "\", "\\")
Str = Replace(Str, CHR(32), " ")
Str = Replace(Str, CHR(34), "\""")
Str = Replace(Str, CHR(39), "'")
Set re=new RegExp
re.IgnoreCase =true
re.Global=True
po=0
ii=0
re.Pattern="(javascript)"
Str=re.Replace(Str,"<I>javascript</I>")
re.Pattern="(jscript:)"
Str=re.Replace(Str,"<I>jscript:</I>")
re.Pattern="(js:)"
Str=re.Replace(Str,"<I>js:</I>")
re.Pattern="(</SCRIPT>)"
Str=re.Replace(Str,"</script>")
re.Pattern="(<SCRIPT)"
Str=re.Replace(Str,"<script")
DealJsText = Str
End if
end Function

'//下面为JS文件 CutArticle.js
var currentSet,CutFlag,TotalByte,PageCount,key,tempText,tempPage;
key="";
currentSet=0;
TotalByte=Text.length;
if (flag==1)
{
PageCount=Math.round(TotalByte/PageSize);
if(parseFloat("0."+TotalByte%PageSize)>0){
if(parseFloat("0."+TotalByte%PageSize)<0.5){
PageCount=PageCount+1;
}
}
var PageNum=new Array(PageCount+1);
var PageTitle=new Array(PageCount+1);
PageNum[0]=0;
PageTitle[0]="";

var sDrv1,sDrv2,sDrv3,sDrv4,sFlag;
var sDrvL,sTemL;
var sTem1,sTem2,k;
sFlag=0;

for(j=1;j<PageCount+1;j++){
PageNum[j]=PageNum[j-1]+PageSize;
PageTitle[j]="";
//alert(j);
sDrv1="<br>";
sDrv2="<BR>";
sDrv3="<Br>";
sDrv4="<bR>";
sDrvL=sDrv1.length;
for(k=PageNum[j];k<=TotalByte;k++){
sTem1=Text.substring(PageNum[j]-sDrvL,k);
sTemL=sTem1.length;
sTem2=sTem1.substring(sTemL-sDrvL,sTemL)
if (sTem2==sDrv1 || sTem2==sDrv2 || sTem2==sDrv3 || sTem2==sDrv4)
{
sFlag=sFlag+1;
PageNum[j]=k;
break;
}
}
if (PageNum[j]>TotalByte)
{
break;
}
}
if (j<PageCount)
{
PageNum.length=j;
PageCount=j
}
if (PageCount>1&&sFlag>1&&PageCount<sFlag)
{
PageCount=sFlag+1;
}
}
else{
//手动分页
var j,sFlag,PageCount,sText;
var sTitleFlag;
var PageNum=new Array();
var PageTitle=new Array();
PageSize=0;
j=1;
PageNum[0]=-10;
PageTitle[0]="";
sFlag=0;
sText=Text;
do
{
sText=Text.substring(PageNum[j-1]+10,TotalByte);
sFlag=sText.indexOf("[NextPage");
if (sText.substring(sFlag+9,sFlag+10)=="=")
{
sTitleFlag=sText.indexOf("]",sFlag);
PageTitle[j]=sText.substring(sFlag+10,sTitleFlag);
}
else{
PageTitle[j]="";
}
if (sFlag>0)
{
PageNum[j]=sFlag+PageNum[j-1]+10;
}
else{
PageNum[j]=TotalByte;
}
j+=1;
}
while (PageNum[j-1]<TotalByte);
PageCount=j-1;
}

function CovertCRLFToBR(s)
{
var i;
var s2 = s;

while(s2.indexOf("[NextPage]")>0)
{
i = s2.indexOf("[NextPage]");
s2 = s2.substring(0, i) + "" + s2.substring(i + 10, s2.length);
}
return s2;
}
function text_pagination(Page){
var Output,Byte;
if(Page==null){Page=1;}
Output="";
Output=Output+"<table width=100% height=30 border=0 align=center cellpadding=0 cellspacing=0>";
Output=Output+"<tr>";
Output=Output+"<td height=1 background=Images/DotLine.gif></td>";
Output=Output+"</tr>";
//头部功能导航条
Output=Output+"<tr>";
//正文查找
Output=Output+"<td align=left width='40%'> ";
Output=Output+"<input type=hidden name=keys class=iptA onchange='key=this.value' size=12> <input type=hidden class=btnA name=search value='查找正文' onclick='searchkey();' style='width:60'>";
Output=Output+"</td>";
Output=Output+"<td align=right>";
//页码显示方式一
//第x页:分页标题
if (Page==0 || PageCount==0){
Output=Output+"当前是:<font color=red>全文显示</font>" ;
}
else{
if(TotalByte>PageSize){Byte=PageNum[Page]-PageNum[Page-1]}else{Byte=TotalByte};
Output=Output+"第 <font color=red>"+Page+"</font> 页";
if (PageTitle[Page]!="")
{
Output=Output+":<font color=800000>"+PageTitle[Page]+"</font>";
}
}
//显示方式二
//下拉菜单选择
//if (PageCount>0)
//{
// Output=Output+PageNav(2,Page);
// Output=Output+" </td>";
//}
//显示方式三
//页码选择列表
//Output=Output+"<td align=right bgcolor=#f0faff>";
//Output=Output+PageNav(0,Page);
//Output=Output+"</td>";
Output=Output+"</tr>";
Output=Output+"<tr>";
Output=Output+"<td height=1 background=Images/DotLine.gif></td>";
Output=Output+"</tr>";
Output=Output+"</table>";
//显示正文
if(Page==0) {
//不分页
tempText=CovertCRLFToBR(Text);
}
else{
//分页
if (flag==1)
//自动分页
{
tempText=Text.substring(PageNum[Page-1],PageNum[Page]);
}
else{
//手动分页
if (PageTitle[Page-1].length==0)
{
tempText=Text.substring(PageNum[Page-1]+10,PageNum[Page]);
}
else{
tempText=Text.substring(PageNum[Page-1]+11+PageTitle[Page-1].length,PageNum[Page]);
}
}
}
Output=Output+"<div id=world>";
Output=Output+tempText;
Output=Output+"</div>";
Output=Output+"<br>";
Output=Output+"<div align=center>";
Output=Output+PageNav(1,Page);
Output=Output+"</div>";

article.innerHTML = Output;
document.location.href='#';
eval(document.all.keys).value=key;
if (key!=""){searchkey();}
}

function searchkey(){
//正文查找函数
h="<font class=keyworld>";
f="</font>";
keyset=new Array();
key=document.all.keys.value;
if (key==""){
alert("请输入关键字!");
return;
}
else{
keyset[0]=tempText.indexOf(key,0);

if (keyset[0]<0){
return;
}else
temp=tempText.substring(0,keyset[0]);
temp=temp+h+key+f;
temp2=tempText.substring(keyset[0]+key.length,tempText.length);
for (i=1;i<tempText.length;i++) {
keyset[i]=tempText.indexOf(key,keyset[i-1]+key.length);
if(keyset[i]<0){
temp=temp+tempText.substring(keyset[i-1]+key.length,tempText.length);
break;
}else{
temp=temp+tempText.substring(keyset[i-1]+key.length,keyset[i])+h+key+f;
}
}
world.innerHTML = temp;
}
}
function PageNav(ShowStyle,Page){
//分页码显示函数
//参数为调用样式,0=简单样式,1=标准样式
var temp="";
if (ShowStyle==0)
//简单样式
{
tempPage=Page;
if(TotalByte>PageSize){
if (Page-4<=1){
temp=temp+"<font face=webdings color=#999999>9</font>";
if (Page<=1){temp=temp+"<font face=webdings color=#999999>7</font>";}else{temp=temp+"<a href=javascript:text_pagination("+(Page-1)+")><font face=webdings>7</font></a>";}
if (PageCount>10){
for(i=1;i<8;i++){
if (i==Page){
temp=temp+"<font color=red>"+i+"</font> ";
}else{
temp=temp+"<a href=javascript:text_pagination("+i+") >"+i+"</a>"+" ";
}
}
temp=temp+" ...";
}
else{
for(i=1;i<PageCount+1;i++){
if (i==Page){
temp=temp+"<font color=red>"+i+"</font> ";
}
else{
temp=temp+"<a href=javascript:text_pagination("+i+") >"+i+"</a>"+" ";
}
}
}
if (Page==PageCount){temp=temp+"<font face=webdings color=#999999>8</font>";}else{temp=temp+"<a href=javascript:text_pagination("+(Page+1)+")><font face=webdings>8</font></a>";}
if(PageCount<10){temp=temp+"<font face=webdings color=#999999>:</font>";}else{temp=temp+"<a href=javascript:text_pagination("+PageCount+")><font face=webdings>:</font></a>";}
}
else if(Page+4<=PageCount){
temp=temp+"<a href=javascript:text_pagination(1)><font face=webdings>9</font></a>";
temp=temp+"<a href=javascript:text_pagination("+(Page-1)+")><font face=webdings>7</font></a>";
if (PageCount>10){
temp=temp+"..";
for(i=Page-4;i<Page+4;i++){
if (i==Page){
temp=temp+"<font color=red>"+i+"</font> ";
}
else{
temp=temp+"<a href=javascript:text_pagination("+i+") >"+i+"</a>"+" ";
}
}
temp=temp+" ..";
}
else{
for(i=1;i<PageCount+1;i++){
if (i==Page){
temp=temp+"<font color=red>"+i+"</font> ";
}
else{
temp=temp+"<a href=javascript:text_pagination("+i+") >"+i+"</a>"+" ";
}
}
}

if (Page==PageCount){temp=temp+"<font face=webdings color=#999999>8</font>";}else{temp=temp+"<a href=javascript:text_pagination("+(Page+1)+")><font face=webdings>8</font></a>";}
temp=temp+"<a href=javascript:text_pagination("+PageCount+")><font face=webdings>:</font></a>";
}
else{
temp=temp+"<a href=javascript:text_pagination(1)><font face=webdings>9</font></a>";
temp=temp+"<a href=javascript:text_pagination("+(Page-1)+")><font face=webdings>7</font></a>";
temp=temp+".."
for(i=Page-2;i<PageCount+1;i++){
if (i==Page){
temp=temp+"<font color=red>"+i+"</font> ";
}
else{
temp=temp+"<a href=javascript:text_pagination("+i+") >"+i+"</a>"+" ";
}
}
if (Page==PageCount){temp=temp+"<font face=webdings color=#999999>8</font>";}else{temp=temp+"<a href=javascript:text_pagination("+(Page+1)+")><font face=webdings>8</font></a>";}
temp=temp+"<font face=webdings color=#999999>:</font>";
}
}
else{
temp=temp+"<font color=red>1</font> ";
}
temp=temp+" <a href=javascript:text_pagination(0)>显示全部</a>"
}
else if (ShowStyle==1)
//标准样式
{
if(TotalByte>PageSize){if(Page!=0){if(Page!=1){temp=temp+"<a href='#top' onclick=javascript:text_pagination("+(Page-1)+")><font color=3366cc>[上一页]</font></a>  ";}}}
for (i=1;i<PageCount+1 ;i++ )
{
if (Page==i)
{
temp=temp+"<font color=800000>["+i+"]</font>  ";
}
else{
temp=temp+"<a href='#top' onclick=javascript:text_pagination("+i+")><font color=3366cc>["+i+"]</font></a>  ";
}
}
temp=temp+"<a name='foot'></a>";
if(TotalByte>PageSize){if(Page!=0){if(Page!=PageCount){temp=temp+"<a href='#top' onclick=javascript:text_pagination("+(Page+1)+")><font color=3366cc>[下一页]</font></a>";}}}
temp=temp+" <a href=javascript:text_pagination(0)><font color=3366cc>显示全部</font></a>"
}
else if (ShowStyle==2)
//下拉菜单样式
{
temp=temp+'<select onchange="text_pagination(this.value)">'
for (i=1;i<PageCount+1 ;i++ )
{
if (Page==i)
{
temp=temp+"<option value='"+i+"' selected style='color:red'>第 "+i+" 页"

}
else{
temp=temp+"<option value='"+i+"'>第 "+i+" 页";
}
if (PageTitle[i].length!=0)
{
temp=temp+':'+PageTitle[i];
}
temp=temp+"</option>";
}
temp=temp+"</select>";
}

return (temp);
}

Javascript 相关文章推荐
jQuery EasyUI API 中文文档 - Panel面板
Sep 30 Javascript
Ext JS 4实现带week(星期)的日期选择控件(实战二)
Aug 21 Javascript
jquery实现input输入框实时输入触发事件代码
Jan 28 Javascript
jquery自动将form表单封装成json的具体实现
Mar 17 Javascript
iframe跨域通信封装详解
Aug 11 Javascript
jQuery实用技巧必备(上)
Nov 02 Javascript
浅谈angularjs module返回对象的坑(推荐)
Oct 21 Javascript
JS中用三种方式实现导航菜单中的二级下拉菜单
Oct 31 Javascript
vue.js中指令Directives详解
Mar 20 Javascript
JS正则替换去空格的方法
Mar 24 Javascript
从零开始搭建webpack+react开发环境的详细步骤
May 18 Javascript
微信小程序中的canvas 文字断行和省略号显示功能的处理方法
Nov 14 Javascript
JS BASE64编码 window.atob(), window.btoa()
Mar 09 #Javascript
JS实现打开本地文件或文件夹
Mar 09 #Javascript
HTML IMG标签 onload 内存溢出导致浏览器CPU占用过高
Mar 09 #Javascript
你可能不再需要JQUERY
Mar 09 #Javascript
JS中剪贴板兼容性、判断复制成功或失败
Mar 09 #Javascript
JS 容错处理代码, 屏蔽错误信息
Mar 09 #Javascript
JAVASCRIPT 对象的创建与使用
Mar 09 #Javascript
You might like
php获取mysql版本的几种方法小结
2008/03/25 PHP
php中mail函数发送邮件失败的解决方法
2014/12/24 PHP
php中使用websocket详解
2016/09/23 PHP
云网广告中的代码,提示出错,大家找找
2006/11/21 Javascript
动态表格Table类的实现
2009/08/26 Javascript
JavaScript接口实现代码 (Interfaces In JavaScript)
2010/06/11 Javascript
jQuery制作简洁的多级联动Select下拉框
2014/12/23 Javascript
javacript使用break内层跳出外层循环分析
2015/01/12 Javascript
js时钟翻牌效果实现代码分享
2020/07/31 Javascript
微信小程序模板之分页滑动栏
2017/02/10 Javascript
基于jQuery实现简单人工智能聊天室
2017/02/10 Javascript
简单谈谈关于Angular Cli打包的事
2017/09/05 Javascript
vue滚动轴插件better-scroll使用详解
2017/10/17 Javascript
JS表单验证插件之数据与逻辑分离操作实例分析【策略模式】
2020/05/01 Javascript
跟老齐学Python之赋值,简单也不简单
2014/09/24 Python
python&amp;MongoDB爬取图书馆借阅记录
2016/02/05 Python
Python数据结构与算法之字典树实现方法示例
2017/12/13 Python
详解python调用cmd命令三种方法
2019/07/08 Python
Python+OpenCV实现实时眼动追踪的示例代码
2019/11/11 Python
使用Pytorch来拟合函数方式
2020/01/14 Python
Python3 io文本及原始流I/O工具用法详解
2020/03/23 Python
python编写一个会算账的脚本的示例代码
2020/06/02 Python
Keras设置以及获取权重的实现
2020/06/19 Python
Python爬虫基于lxml解决数据编码乱码问题
2020/07/31 Python
python与js主要区别点总结
2020/09/13 Python
python在地图上画比例的实例详解
2020/11/13 Python
浅析HTML5 meta viewport参数
2020/10/28 HTML / CSS
会计员岗位职责
2014/03/15 职场文书
2014年纠风工作总结
2014/12/08 职场文书
写给妈妈的感谢信
2015/01/22 职场文书
同学聚会通知书
2015/04/20 职场文书
驳回起诉裁定书
2015/05/19 职场文书
2015年中职班主任工作总结
2015/05/25 职场文书
阿里云服务器部署mongodb的详细过程
2021/09/04 MongoDB
一篇文章带你掌握SQLite3基本用法
2022/06/14 数据库
Java实现贪吃蛇游戏的示例代码
2022/09/23 Java/Android