下面图老师小编要跟大家分享使用javascript+xml技术实现分页浏览,简单的过程中其实暗藏玄机,还是要细心学习,喜欢还请记得收藏哦!
【 tulaoshi.com - Web开发 】
基于web的技术中,分页是一个老的不能再老的,但大家津津乐道的问题,随着xml技术的日渐应用,把xml应用到分页当中,也是一种可能,当然网上的教程很多,当我都是看得稀里糊涂,索性自己写一个,与大家分享、指正。
共有两个文件tmh.htm & tt.xml
源代码如下:
tmh.htm
___________________________________________________
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
HTML
HEAD
TITLE New Document /TITLE
META NAME="Generator" CONTENT="EditPlus"
META NAME="Author" CONTENT=""
META NAME="Keywords" CONTENT=""
META NAME="Description" CONTENT=""
link rel="stylesheet" href="../website.css" type="text/css"
/HEAD
BODY
script language="javascript"
//****************变量相关定义**************
//* author:海仔 *
//* Email:rautinee@21cn.com *
//*本程序可自由传播使用,但请务必保留此信息*
//****************************************
var pagenum=4; //每页显示几条信息
var page=0 ;
var contpage ;
var BodyText="";
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
var mode="member";
var toolBar;
xmlDoc.async="false"
xmlDoc.load("tt.xml")
//***************这个地方是你根据实际取得的字段名称来改了
header="TABLE border=1trtd姓名/tdtd图标/tdtdIP地址/tdtdemail/tdtd/tdtd日期/tdtd/tdtd/td/tr";
//检索的记录数
maxNum = xmlDoc.getElementsByTagName(mode).length
//每条记录的列数
column=xmlDoc.getElementsByTagName(mode).item(0).childNodes
//每条记录的列数
colNum=column.length
//页数
pagesNumber=Math.ceil(maxNum/pagenum)-1;
pagesNumber2=Math.ceil(maxNum/pagenum);
//上一个页面
function UpPage(page)
{
thePage="前一页";
if(page+11) thePage="A HREF='#' onclick='Javascript:return UpPageGo()'前一页/A";
return thePage;
}
function NextPage(page)
{
thePage="后一页";
if(pagepagesNumber) thePage="A HREF='#' onclick='Javascript:return NextPageGo()'后一页/A";
return thePage;
}
function UpPageGo(){
if(page0) page--;
getContent();
BodyText="";
}
//下面是tt.xml的代码
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)?xml version="1.0" encoding="GB2312"?
rautinee
member id='1'
name海仔/name
loginNamerautinee/loginName
emailrautinee@btamail.net.cn/email/member
member id='2'
name刚强/name
loginNamehehe/loginName
emailrautinee@chinamanagers.com/email/member
member id='3'
name金华刚/name
loginNamenature_it/loginName
emailrautinee_sea@hotmail.com/email/member
member id='4'
name的简强/name
loginNametank/loginName
emailtank@163.com/email/member
member id='7'
name合资/name
loginNamekaka/loginName
emailkaka@eyou.com/email/member
member id='6'
name加个人/name
loginNameapple/loginName
emailapple@163.com/email/member
member id='8'
namenull/name
loginNamesunny/loginName
emailrautinee@eyou.com/email/member
member id='10'
name宝贝/name
loginNameindex/loginName
emailrautinee@21cn.com/email/member
member id='12'
namenull/name
loginNamelogin/loginName
emailwebmaster@chinamanagers.com/email/member
member id='13'
namejiang/name
loginName123/loginName
emailjaping@chianmanagers.com/email/member
member id='14'
namenull/name
loginNameworld/loginName
emailrautinee@21cn.com/email/member
member id='15'
namenull/name
loginNameswallow/loginName
emailswallow@chinamanagers.com/email/member
member id='16'
name魏格/name
loginNamehotmail/loginName
emailrautinee_sea@hotmail.com/email/member
member id='17'
namenull/name
loginNamewrong/loginName
emailwrong@chinamanagers.com/email/member
member id='18'
namenull/name
loginNameleah/loginName
emailleah@chinamanagers.com/email/member
member id='19'
namenull/name
loginNamettth/loginName
emailrautinee@21cn.com/email/member
/rautinee
目前好像是只支持IE5.0
如果你有什么好的方法和改进,请来信通知我,谢谢。
来源:http://www.tulaoshi.com/n/20160219/1622545.html
看过《使用javascript+xml技术实现分页浏览》的人还看了以下文章 更多>>