Home Web Front-end JS Tutorial JavaScript operation XML example code (get news titles and paginate, and paginate)_javascript skills

JavaScript operation XML example code (get news titles and paginate, and paginate)_javascript skills

May 16, 2016 pm 06:26 PM
javascript xml Pagination

I haven't tested the specific content. For reference only
Code

Copy code The code is as follows:




News Test 1 News Test 1


News Test 2 News Test 2


News Test 3 News Test 3


News Test 4 News Test 4


News Test 5 News Test 5


News Test 6 News Test 6


News Test 7 News Test 7


News Test 8 News Test 8

News Test 9 News Test 9



JS code part. The js part of the code is relatively simple. The most important ones are the XML operation functions
Copy the code The code is as follows:

//JavaScript
function bindNew(index)
{
var List = new Array();
List = showPage(index);
var listul = "
    "
    for( var i=0 ; i < List.length ; i )
    {
    //document.getElementById("listTb").innerHTML = List[i] "
    ";
    listul = "
  • " List[i] "
  • ";
    }
    listul = "
";
document.getElementById("listTb").innerHTML = listul;
document.getElementById("refer").innerHTML = "";
var tc = rtnPageCount();
for( var i=1 ; i<=tc ; i )
{
//

document.getElementById("refer").innerHTML = "
" i "
";
}
}
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.resolveExternals = false;
xmlDoc.load("News.xml");
// 返回固定 ID 的新闻
function findNew(newid)
{
var Domelement = xmlDoc.documentElement;
alert(Domelement);
}
// 返回分页后的新闻标题连接
var pageSize = 40;
function showPage(pageIndex)
{
var Alltt = new Array();
Alltt = AlltitleLink();
var rtLinks = new Array();
/*未完成部分*/
try
{
for( var i=0 ; i< pageSize && (pageSize*(pageIndex-1) i){
rtLinks[i] = Alltt[pageSize*(pageIndex-1) i];
}
}
catch(e)
{ alert("showPage() 方法出错 !"); }
return rtLinks;
}
//返分页后的页数
function rtnPageCount()
{
var countx = getCount();
if(countx%pageSize == 0)
{
return countx/pageSize ;
}
else
{
return countx/pageSize 1 ;
}
}
//返回新闻条数
function getCount()
{
var NewRoot = xmlDoc.documentElement;
var AllNews = NewRoot.childNodes;
return AllNews.length;
}
//返回固定条数的新闻标题连接
function returnNews(count)
{
var titles = new Array();
var j = 0;
NewRoot = xmlDoc.documentElement;
allNews = NewRoot.childNodes;
for( var i=0 ; i{
if(i >= allNews.lenth)
{
titles[j] = "" allNews[i].getArrtibute("name") "";
j ;
}
}
return titles;
}
//发回所有新闻 标题的超连接
function AlltitleLink()
{
var allttLink = new Array();
var NewRoot = xmlDoc.documentElement ;
var allNews = NewRoot.childNodes;
for( var i=0 ; i{
var context = allNews[i];
allttLink[i] = "" context.getAttribute("time") " : " context.getAttribute("name") "";
}
return allttLink;
}

部分Html 代码
复制代码 代码如下:











全部动态>>




希望对大家的学习工作又所帮助, 欢迎提问反馈
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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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

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.

Best way to implement array pagination in PHP Best way to implement array pagination in PHP May 04, 2024 pm 02:39 PM

There are two most common ways to paginate PHP arrays: using the array_slice() function: calculate the number of elements to skip, and then extract the specified range of elements. Use built-in iterators: implement the Iterator interface, and the rewind(), key(), current(), next(), and valid() methods are used to traverse elements within the specified range.

How to get HTTP status code in JavaScript the easy way How to get HTTP status code in JavaScript the easy way Jan 05, 2024 pm 01:37 PM

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service

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