Home Backend Development XML/RSS Tutorial Detailed introduction on how to use javascript+xml to implement paging

Detailed introduction on how to use javascript+xml to implement paging

Mar 06, 2017 pm 04:38 PM

In web-based technology, paging is an old problem, but it is a problem that everyone talks about. With the increasing application of xml technology, it is also possible to apply xml to paging. Of course, online There are a lot of tutorials, but I looked at them all in confusion, so I decided to write one myself and share and correct them with everyone.
There are two files tmh.htm & tt.xml
The source code is as follows:
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=1><tr><td>姓名</td><td>图标</td><td>IP地址</td><td>email</td><td></td><td>日期</td><td></td><td></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+1>1) thePage="<A HREF=&#39;#&#39; onclick=&#39;Javascript:return UpPageGo()&#39;>前一页</A>";
    return thePage;
}
function NextPage(page)
{
    thePage="后一页";
    if(page<pagesNumber) thePage="<A HREF=&#39;#&#39; onclick=&#39;Javascript:return NextPageGo()&#39;>后一页</A>";
    return thePage;
}

function UpPageGo(){ 

if(page>0) page--; 
    getContent(); 
    BodyText=""; 

} 
//当前的页数
function currentPage()
{
    var cp;
    cp="当前是第 "+(page+1)+" 页";
    return cp;
}
//总共的页数
function allPage()
{
    var ap;
    ap=&#39;总共 &#39;+(pagesNumber+1)+&#39; 页&#39;;
    return ap
}
function NextPageGo()
{ 
if (page<pagesNumber) page++;

    getContent(); 
    BodyText="";
} 

//显示分页状态栏
function pageBar(page)
{
    var pb;
    pb=UpPage(page)+"  "+NextPage(page)+"  "+currentPage()+"  "+allPage()+selectPage();
    return pb;
}
function changePage(tpage)
{    

    page=tpage
    if(page>=0) page--; 
    if (page<pagesNumber) page++;
    getContent(); 
    BodyText="";
}
function selectPage()
{
    var sp;
    sp="<select name=&#39;hehe&#39; onChange=&#39;javascript:changePage(this.options[this.selectedIndex].value)&#39;>";
    //sp="<select name=&#39;hehe&#39; onChange=&#39;alert(this.options[this.selectedIndex].value)&#39;>";
    sp=sp+"<option value=&#39;&#39;></option>";
    for (t=0;t<=pagesNumber;t++)
    {
        sp=sp+"<option value=&#39;"+t+"&#39;>"+(t+1)+"</option>";
    }
    sp=sp+"</select>"
    return sp;
}

function getContent()
{

        if (!page) page=0;
        n=page*pagenum;
        endNum=(page+1)*pagenum;
        if (endNum>maxNum) endNum=maxNum;
        BodyText=header+BodyText;
        for (;n<endNum;n++)
        {
            
            BodyText=BodyText+"<TR>";
                for (m=0;m<=colNum-1;m++)
                {    
                    mName=column.item(m).tagName;
                    BodyText=BodyText+("<TD>"+xmlDoc.getElementsByTagName(mName).item(n).text+"</TD>");
                }
            BodyText=BodyText+"</TR>"
            mm="";
            }
            showhtml.innerHTML=BodyText+"</table>"+pageBar(page); 

BodyText=""
}
</script> 

<div id="showhtml"></div>
<script>
if (maxNum==0)
        {
            document.write("没有检索到合适的人才信息")
        }
    else
        {
            getContent()
        }
</script>

</BODY>
</HTML>

//下面是tt.xml的代码




<?xml version="1.0" encoding="GB2312"?>
<rautinee>

<member id=&#39;1&#39;> 
<name>海仔</name>
<loginName>rautinee</loginName>
<email>rautinee@btamail.net.cn</email></member>

<member id=&#39;2&#39;>
<name>刚强</name>
<loginName>hehe</loginName>
<email>rautinee@chinamanagers.com</email></member>

<member id=&#39;3&#39;>
<name>金华刚</name>
<loginName>nature_it</loginName>
<email>rautinee_sea@hotmail.com</email></member>

<member id=&#39;4&#39;>
<name>的简强</name>
<loginName>tank</loginName>
<email>tank@163.com</email></member>

<member id=&#39;7&#39;>
<name>合资</name>
<loginName>kaka</loginName>
<email>kaka@eyou.com</email></member>

<member id=&#39;6&#39;>
<name>加个人</name>
<loginName>apple</loginName>
<email>apple@163.com</email></member>

<member id=&#39;8&#39;>
<name>null</name>
<loginName>sunny</loginName>
<email>rautinee@eyou.com</email></member>

<member id=&#39;10&#39;>
<name>宝贝</name>
<loginName>index</loginName>
<email>rautinee@21cn.com</email></member>

<member id=&#39;12&#39;>
<name>null</name>
<loginName>login</loginName>
<email>webmaster@chinamanagers.com</email></member>

<member id=&#39;13&#39;>
<name>jiang</name>
<loginName>123</loginName>
<email>japing@chianmanagers.com</email></member>

<member id=&#39;14&#39;>
<name>null</name>
<loginName>world</loginName>
<email>rautinee@21cn.com</email></member>

<member id=&#39;15&#39;>
<name>null</name>
<loginName>swallow</loginName>
<email>swallow@chinamanagers.com</email></member>

<member id=&#39;16&#39;>
<name>魏格</name>
<loginName>hotmail</loginName>
<email>rautinee_sea@hotmail.com</email></member>

<member id=&#39;17&#39;>
<name>null</name>
<loginName>wrong</loginName>
<email>wrong@chinamanagers.com</email></member>

<member id=&#39;18&#39;>
<name>null</name>
<loginName>leah</loginName>
<email>leah@chinamanagers.com</email></member>

<member id=&#39;19&#39;>
<name>null</name>
<loginName>ttth</loginName>
<email>rautinee@21cn.com</email></member>

</rautinee>
Copy after login

Currently it seems that it only supports>IE5.0

The above is a detailed introduction on how to use javascript+xml to implement paging. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Can I open an XML file using PowerPoint? Can I open an XML file using PowerPoint? Feb 19, 2024 pm 09:06 PM

Can XML files be opened with PPT? XML, Extensible Markup Language (Extensible Markup Language), is a universal markup language that is widely used in data exchange and data storage. Compared with HTML, XML is more flexible and can define its own tags and data structures, making the storage and exchange of data more convenient and unified. PPT, or PowerPoint, is a software developed by Microsoft for creating presentations. It provides a comprehensive way of

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

JavaScript and WebSocket: Building an efficient real-time weather forecasting system JavaScript and WebSocket: Building an efficient real-time weather forecasting system Dec 17, 2023 pm 05:13 PM

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

Detailed explanation of the principle of MyBatis paging plug-in Detailed explanation of the principle of MyBatis paging plug-in Feb 22, 2024 pm 03:42 PM

MyBatis is an excellent persistence layer framework. It supports database operations based on XML and annotations. It is simple and easy to use. It also provides a rich plug-in mechanism. Among them, the paging plug-in is one of the more frequently used plug-ins. This article will delve into the principles of the MyBatis paging plug-in and illustrate it with specific code examples. 1. Paging plug-in principle MyBatis itself does not provide native paging function, but you can use plug-ins to implement paging queries. The principle of paging plug-in is mainly to intercept MyBatis

How to use PHP functions to process XML data? How to use PHP functions to process XML data? May 05, 2024 am 09:15 AM

Use PHPXML functions to process XML data: Parse XML data: simplexml_load_file() and simplexml_load_string() load XML files or strings. Access XML data: Use the properties and methods of the SimpleXML object to obtain element names, attribute values, and subelements. Modify XML data: add new elements and attributes using the addChild() and addAttribute() methods. Serialized XML data: The asXML() method converts a SimpleXML object into an XML string. Practical example: parse product feed XML, extract product information, transform and store it into a database.

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Comparison of Java libraries for XML parsing: Finding the best solution Comparison of Java libraries for XML parsing: Finding the best solution Mar 09, 2024 am 09:10 AM

Introduction XML (Extensible Markup Language) is a popular format for storing and transmitting data. Parsing XML in Java is a necessary task for many applications, from data exchange to document processing. To parse XML efficiently, developers can use various Java libraries. This article will compare some of the most popular XML parsing libraries, focusing on their features, functionality, and performance to help developers make an informed choice. DOM (Document Object Model) parsing library JavaXMLDOMAPI: a standard DOM implementation provided by Oracle. It provides an object model that allows developers to access and manipulate XML documents. DocumentBuilderFactoryfactory=D

See all articles