JS+ASP实现无刷新新闻列表之分页
作者:dnawo 来源:mzwu.com 发布时间:2007-08-22 12:57:00
标签:无刷新,ASP,JS,分页
上次用Javascript+ASP实现了无刷新的新闻列表,最后还有一个小问题没有解决:下边的分页数列"首页、上10页、下10页、尾页"间怎么切换?你应该不会想用传统的方法用ASP进行查询然后显示数列吧?那我们之前对无刷新所做的努力可就全白费了!
你首先应该想到的是再用Javascript+ASP实现无刷新显示数列,但这次我们也不用这个,我们有更简单的方法。
使用Javascript+ASP来显示分页数列的话那切换一次就得重新查询一次数据库,完全没有必要!我们只需在打开新闻列表页时查询一次数据库,将总页数保存起来(比如保存在一个隐藏的表单中),以后列表的切换工作就交给Javascript了,还是Javascript+ASP,不过本质不一样了哦,先前是同步,这次是异步了。
具体过程:
1.在页面中新建两个隐藏的表单域,其中一个用于存放当前列表的最后一项,另一个用于存放总页数:
<input name="endid" id="endid" type="hidden" value="0">
<input name="countnews" id="countpage" type="hidden" value="0">
2.新建div标签用于存放分页数列:
<div id="pageNews"></div>
3.加入Javascript脚本:
//首页
function first(){
var table,endid,countpage,i;
endid = parseInt(document.getElementById("endid").value);
countpage = parseInt(document.getElementById("countpage").value);
table = "<table height=’20’ border=’0’ align=’center’ cellpadding=’0’ cellspacing=’0’><tr>";
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:first();’><img src=’images/First.gif’ width=’9’ height=’8’ border=’0’ title=’首页’></a></td>";
if(countpage<=10){
for(i=1;i<=countpage;i++){
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:showpage(" + i + ");’>" + i + "</a></td>";
}
document.getElementById("endid").value = countpage;
}else{
for(i=1;i<=10;i++){
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:showpage(" + i + ");’>" + i + "</a></td>";
}
document.getElementById("endid").value = "10";
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:next();’><img src=’images/Next.gif’ width=’8’ height=’8’ border=’0’title=’下10页’></a></td>"
}
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:last();’><img src=’images/Last.gif’ width=’9’ height=’8’ border=’0’title=’尾页’></a></td>";
table += "</tr></table>";
document.getElementById("pageNews").innerHTML = table;
}
//上10页
function previous(){
var table,endid,countpage,i;
endid = parseInt(document.getElementById("endid").value);
countpage = parseInt(document.getElementById("countpage").value);
table = "<table height=’20’ border=’0’ align=’center’ cellpadding=’0’ cellspacing=’0’><tr>";
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:first();’><img src=’images/First.gif’ width=’9’ height=’8’ border=’0’ title=’首页’></a></td>";
if(endid-20<1){
for(i=1;i<=10;i++){
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:showpage(" + i + ");’>" + i + "</a></td>";
}
document.getElementById("endid").value = "10";
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:next();’><img src=’images/Next.gif’ width=’8’ height=’8’ border=’0’title=’下10页’></a></td>"
}else{
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:previous();’><img src=’images/Previous.gif’ width=’8’ height=’8’ border=’0’title=’上10页’></a></td>";
for(i = endid-19;i<= endid-10;i++){
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:showpage(" + i + ");’>" + i + "</a></td>";
}
document.getElementById("endid").value = endid-10;
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:next();’><img src=’images/Next.gif’ width=’8’ height=’8’ border=’0’title=’下10页’></a></td>"
}
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:last();’><img src=’images/Last.gif’ width=’9’ height=’8’ border=’0’title=’尾页’></a></td>";
table += "</tr></table>";
document.getElementById("pageNews").innerHTML = table;
}
//下10页
function next(){
var endid,table,countpage,i;
endid = parseInt(document.getElementById("endid").value);
countpage = parseInt(document.getElementById("countpage").value);
table = "<table height=’20’ border=’0’ align=’center’ cellpadding=’0’ cellspacing=’0’><tr>";
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:first();’><img src=’images/First.gif’ width=’9’ height=’8’ border=’0’ title=’首页’></a></td>";
if(endid + 10>countpage){
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:previous();’><img src=’images/Previous.gif’ width=’8’ height=’8’ border=’0’title=’上10页’></a></td>";
for(i=endid + 1;i<=countpage;i++){
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:showpage(" + i + ");’>" + i + "</a></td>";
}
document.getElementById("endid").value = countpage;
}else{
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:previous();’><img src=’images/Previous.gif’ width=’8’ height=’8’ border=’0’title=’上10页’></a></td>";
for(i=endid + 1;i<=endid + 10;i++){
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:showpage(" + i + ");’>" + i + "</a></td>";
}
document.getElementById("endid").value = endid + 10;
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:next();’><img src=’images/Next.gif’ width=’8’ height=’8’ border=’0’title=’下10页’></a></td>"
}
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:last();’><img src=’images/Last.gif’ width=’9’ height=’8’ border=’0’title=’尾页’></a></td>";
table += "</tr></table>";
document.getElementById("pageNews").innerHTML = table;
}
//尾页
function last(){
var table,endid,countpage,i;
endid = parseInt(document.getElementById("endid").value);
countpage = parseInt(document.getElementById("countpage").value);
table = "<table height=’20’ border=’0’ align=’center’ cellpadding=’0’ cellspacing=’0’><tr>";
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:first();’><img src=’images/First.gif’ width=’9’ height=’8’ border=’0’ title=’首页’></a></td>";
if(countpage<=10){
for(i=1;i<=countpage;i++){
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:showpage(" + i + ");’>" + i + "</a></td>";
}
document.getElementById("endid").value = countpage;
}else{
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:previous();’><img src=’images/Previous.gif’ width=’8’ height=’8’ border=’0’title=’上10页’></a></td>";
for(i=countpage - 9;i<=countpage;i++){
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:showpage(" + i + ");’>" + i + "</a></td>";
}
document.getElementById("endid").value = countpage;
}
table += "<td width=’20’ align=’center’ valign=’middle’><a href=’javascript:last();’><img src=’images/Last.gif’ width=’9’ height=’8’ border=’0’title=’尾页’></a></td>";
table += "</tr></table>";
document.getElementById("pageNews").innerHTML = table;
}
4.将<script language="JavaScript" type="text/javascript">first();</script>放在<div id="pageNews"></div>后,用于初始化分页列表并将结果显示于div中。
5.在news.asp中加入程序,在页面打开时查询数据库,并将总页数保存于countnews中.
至此,整个新闻列表显示页就完整了。最后说一句:凡事,首先从简单的出发...
相关阅读:


猜你喜欢
- 前言在开发中一些需求需要通过程序操作excel文档,例如导出excel、导入excel、向excel文档中插入图片、表格和图表等信息,使用E
- #!#backup.sh##系统名称sysname=gzsyspath=/home/oracle/databak/$sysname/v_da
- 说明1、字典运算中的键必须是不可变类型,如整数(int)、浮点数(float)、字符串(str)、元组(tuple)等。2、列表(list)
- 这篇博客将介绍如何使用OpenCV和深度学习应用全面嵌套的边缘检测。并将对图像和视频流应用全面嵌套边缘检测,然后将结果与OpenCV的标准C
- 写的dht协议搜索的程序,这几天优化了一下发现速度确实快了好多。但是出现了一个新的问题,内存直接飙升,我开了十个爬虫占用内存800m。开始我
- ASP中转换unicode编码为GB编码方法:<% function urldecode(encodestr)
- Python zfill()方法返回指定长度的字符串,原字符串右对齐,前面填充0。zfill()方法语法:str.zfill(width)参
- tensorflow对图像进行多个块的行列拼接tf.concat(), tf.stack()在深度学习过程中,通过卷积得到的图像块大小是8×
- GO通道和 sync 包的分享我们一起回顾一下上次分享的内容:GO协程同步若不做限制的话,会产生数据竞态的问题我们用锁的方式来解决如上问题,
- 不知各位是否有手写代码的习惯。例如:要在一个单元格插入一段CSS代码,或者一段Javascript代码,怎么做才比较快捷方便呢?虽然Drea
- 本文实例总结了php处理json格式数据的方法。分享给大家供大家参考,具体如下:1.json简介:何为json?简 单地说,JSON 可以将
- 我就废话不多说了,直接上代码吧!import matplotlibmatplotlib.use('Agg')import o
- 1.假设已经有mysql-5.5.10.tar.gz以及cmake-2.8.4.tar.gz两个源文件(1)先安装cmake(mysql5.
- 目录1. 字典基础知识字典的基本格式表示字典的键、值设置要求1)键的设置要求2)值的设置要求2. 字典元素增加1.利用赋值给字典增加元素2.
- 在任何编辑器中,获取光标位置都是非常重要的,很多人可能认为较难,其实只要处理好浏览器的兼容,还是比较容易实现的。下面我们一起来看看如何获取到
- 本文主要研究的是flask使用session保存登录状态及拦截未登录请求的相关内容,具体介绍如下。前端请求form:<form act
- 今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显。关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我们
- 文章主要描述的是SQL Server聚集索引的指示(Cluster Index Indications),在实际操作中借助聚集索引来进行搜索
- 设置Table的细边框通常有这么几种方式:1、设置边框的BORDER=0 、cellspacing=1,设置Table的背景色为所要的边框色
- ASP中判断字符串中是否包含字母和数字的两个函数function isnaw(str) for