Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 18:26:34
Original
1091 people have browsed it

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 代码
复制代码 代码如下:











全部动态>>




希望对大家的学习工作又所帮助, 欢迎提问反馈
Related labels:
source: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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template