- 爱易网页
-
JavaSript
- 能不能把最前面那段JS放进一个FUNCTION里面.当页面载入时调用.该如何处理
日期:2014-05-16 浏览次数:20434 次
能不能把最前面那段JS放进一个FUNCTION里面...当页面载入时调用...急
<html>
<head>
<title> javascript读取RSS数据 </title>
<META content= "text/html; charset=utf-8 " http-equiv=Content-Type />
</head>
<body leftmargin= "0 " topmargin= "0 " >
<font> <h3 align= "center "> javascript读取RSS数据 </h3> </font>
<br>
<div id= "container " > News Loading... </div>
<script language= "JavaScript1.2 ">
if (window.ActiveXObject)
{
//document.write( "Microsoft.XMLDOM ");
var xmlDoc = new ActiveXObject( "Microsoft.XMLDOM ");
}
else if (document.implementation && document.implementation.createDocument)
{
//document.write( "document.implementation.createDocument ");
var xmlDoc= document.implementation.createDocument( " ", "doc ",null);
}
if (typeof xmlDoc!= "undefined ")
{
var xmlsource= "http://rss.xinhuanet.com/rss/it.xml ";
//document.write(tickercontainer)
xmlDoc.load(xmlsource)
//alert(xmlDoc);
fetchxml();
xmlDoc.onload=output;
}
function fetchxml()
{
if (xmlDoc.readyState==4)
//document.write( "fdfdf ");
output();
else
setTimeout( "fetchxml() ",10);
}
function output()
{
var root;
var title;
var link;
var items;
var item;
var temp= " ";
root = xmlDoc.getElementsByTagName( "channel ")[0];
title =root.getElementsByTagName( "title ")[0];
//temp = title.firstChild.nodeValue + " <br> ";
items=root.getElementsByTagName( "item ");
for(i=0;i <=items.length-1;i++)
{
item=items[i];
title=item.getElementsByTagName( "title ")[0];
link=item.getElementsByTagName( "link ")[0];
//alert(link.firstChild.nodeValue);
temp = temp + " <font size=-1> <a href= " + link.firstChild.nodeValue+ " target= '_bank '> " +title.firstChild.nodeValue+ " <br> "+ " </a> </font> ";
//temp = temp + " <font size=-1> " + description.firstChild.nodeValue + " </font> <br> <br> ";
document.getElementById( "container ").innerHTML = temp;
//alert(link.firstChild.nodeValue);
//test(link.firstChild.nodeValue);
}
//setTimeout(output(),1000)