新闻内页-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 相关文章推荐
仿163填写邮件地址自动显示下拉(无优化)
Nov 05 Javascript
判断JS对象是否拥有某种属性的两种方式
Dec 02 Javascript
使用jQuery动态加载js脚本文件的方法
Apr 03 Javascript
删除条目时弹出的确认对话框
Jun 05 Javascript
js+html5实现canvas绘制圆形图案的方法
Jun 05 Javascript
Angular2 多级注入器详解及实例
Oct 30 Javascript
浅谈Vue的基本应用
Dec 27 Javascript
vue如何引用其他组件(css和js)
Apr 13 Javascript
jQuery实现的弹幕效果完整实例
Sep 06 jQuery
vue 监听屏幕高度的实例
Sep 05 Javascript
js实现全选反选不选功能代码详解
Apr 24 Javascript
对layer弹出框中icon数字参数的说明介绍
Sep 04 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中file_get_contents与curl性能比较分析
2014/11/08 PHP
php解析xml 的四种简单方法(附实例)
2016/07/11 PHP
分享一个asp.net pager分页控件
2012/01/04 Javascript
javascript页面上使用动态时间具体实现
2014/03/18 Javascript
使用jquery实现以post打开新窗口
2014/03/19 Javascript
浅谈js的url解析函数封装
2016/06/28 Javascript
使用vue.js实现checkbox的全选和多个的删除功能
2017/02/17 Javascript
ES6新特性三: Generator(生成器)函数详解
2017/04/21 Javascript
React Native模块之Permissions权限申请的实例相机
2017/09/28 Javascript
JS中this的4种绑定规则详解
2020/02/04 Javascript
详解JavaScript数据类型和判断方法
2020/09/04 Javascript
使用python3+xlrd解析Excel的实例
2018/05/04 Python
tensorflow 加载部分变量的实例讲解
2018/07/27 Python
python斐波那契数列的计算方法
2018/09/27 Python
Python使用gRPC传输协议教程
2018/10/16 Python
python 递归深度优先搜索与广度优先搜索算法模拟实现
2018/10/22 Python
Python实现读取txt文件中的数据并绘制出图形操作示例
2019/02/26 Python
python实现微信自动回复及批量添加好友功能
2019/07/03 Python
python pandas获取csv指定行 列的操作方法
2019/07/12 Python
Python破解BiliBili滑块验证码的思路详解(完美避开人机识别)
2020/02/17 Python
python+Selenium自动化测试——输入,点击操作
2020/03/06 Python
python3 googletrans超时报错问题及翻译工具优化方案 附源码
2020/12/23 Python
Under Armour安德玛法国官网:美国高端运动科技品牌
2018/06/29 全球购物
意大利灯具购物网站:Lampade.it
2018/10/18 全球购物
上海方立数码笔试题
2013/10/18 面试题
Java中的基本数据类型所占存储空间大小固定的吗
2012/02/15 面试题
造价工程师个人求职信
2013/09/21 职场文书
生物科学专业个人求职信范文
2013/12/07 职场文书
建筑经济管理专业求职信分享
2014/01/06 职场文书
项目施工员岗位职责
2014/03/09 职场文书
社区志愿者活动总结
2014/06/26 职场文书
教师职位说明书
2014/07/29 职场文书
食品安全演讲稿
2014/09/01 职场文书
2014年公务员转正工作总结
2014/11/07 职场文书
2016新年问候语大全
2015/11/11 职场文书
深入探讨opencv图像矫正算法实战
2021/05/21 Python