支持分页的 Javascript 新闻列表脚本
作者:parno 日期:2009-11-17
早咯辰光写咯一个显示新闻列表咯脚本,算是蛮有通用性,放嗯达备份。
news.js
在网页里插入上面各 js 文件,调用辰光用写:
news.js
复制内容到剪贴板 程序代码
// JavaScript Document
var cpage = 0; //当前页
var tpages = 0; //总页数
var ViewNum = 0;
function writeNewsList(ViewNum,PageCur) {
var newtmp = new Array();
var newlst = new Array();
var htmstr = "
document.getElementById("newsContent").innerHTML = htmstr;
if(document.getElementById("cPage")) document.getElementById("cPage").innerHTML = cpage + 1;
}
function writePage(){
var htmstr = "
document.getElementById("PageContent").innerHTML = htmstr;
}
var cpage = 0; //当前页
var tpages = 0; //总页数
var ViewNum = 0;
function writeNewsList(ViewNum,PageCur) {
var newtmp = new Array();
var newlst = new Array();
var htmstr = "
- " //输出HTML
- ";
if(newtmp[2] != ""){
htmstr += "" + newtmp[0] + "";
}else{
htmstr += newtmp[0];
}
if(newtmp[1] != "") {
htmstr += "(" + newtmp[1] + ")" + " ";
var nstart = 0; //选择启始新闻
if(ViewNum <= 0) ViewNum = 10;
newlst[0] = "新闻标题一|2003-11-10|040501.htm"
newlst[1] = "新闻标题二|2003-11-10|040502.htm"
newlst[2] = "新闻标题三|2003-11-10|040503.htm"
newlst[3] = "新闻标题四|2003-11-10|040504.htm"
newlst[4] = "新闻标题五|2003-10-12|040505.htm"
newlst[5] = "新闻标题六|2004-05-01|040506.htm"
newlst[6] = "新闻标题七|2004-05-01|040507.htm"
newlst[7] = "新闻标题八|2005-03-01|040508.htm"
newlst[8] = "新闻标题九|2005-05-03|040509.htm"
newlst[9] = "新闻标题十|2005-09|"
newlst[10] = "新闻标题十一|2005-09|"
newlst[11] = "新闻标题|2005-12|"
//添加新闻在这里
//新闻数据格式:标题|时间|URL
// 时间格式甭检查阿是有效咯,URL 空也来是
newlst = newlst.reverse();
//tpages = Math.ceil((newlst.length - 1) / ViewNum) - 1; //0起计算
tpages = Math.ceil((newlst.length - 1) / ViewNum);
if(PageCur == 0) cpage = 0; //首页
if(PageCur == -1) cpage = cpage - 1; //上页
if(PageCur == 1) cpage = cpage + 1; //下载
if(PageCur == 2) cpage = tpages; //尾页
if(cpage < 0) cpage = 0;
if(cpage > tpages) cpage = tpages;
nstart = ViewNum * cpage;
for(var i = nstart; i < ViewNum + nstart; i ++){
if(i < newlst.length){
newtmp = newlst[i].split("|");
htmstr += "
}else{
htmstr += "";
}
}
}
htmstr += "
document.getElementById("newsContent").innerHTML = htmstr;
if(document.getElementById("cPage")) document.getElementById("cPage").innerHTML = cpage + 1;
}
function writePage(){
var htmstr = "
当前第 " + (cpage + 1) + " 页 / 总共 " + (tpages + 1) + " 页 ";
htmstr += "首 页" + " ";
htmstr += "上一页" + " ";
htmstr += "下一页" + " ";
htmstr += "尾 页" + "
";htmstr += "首 页" + " ";
htmstr += "上一页" + " ";
htmstr += "下一页" + " ";
htmstr += "尾 页" + "
document.getElementById("PageContent").innerHTML = htmstr;
}
在网页里插入上面各 js 文件,调用辰光用写:
复制内容到剪贴板 程序代码
正在加载新闻标题...
正在加载页码...
[本日志由 parno 于 2010-04-06 10:52 PM 编辑]
上一篇: Flash & Ajax 操作 XML 实例 - 无刷新分页下一篇: VisualBasic.NET 连接数据库的几种方法
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: javascript
相关日志:
评论: 0 | 引用: 0 | 查看次数: 6373
发表评论