<html>
<head>
<title>javascript读取RSS数据</title>
<META content="text/html; charset=utf-8" http-equiv=Content-Type />
</head>
<body  leftmargin="0" topmargin="0" onload=aaa()> 
<font><h3 align="center">javascript读取RSS数据</h3></font>
<br>  
<div id="container" >News Loading...</div>
<script language="JavaScript1.2">
function aaa(){
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)
}
</script>  
 
</body>
</html>

解决方案 »

  1.   

    to yejianmin:
    报什么错撒?
    是不是变量未定义?
      

  2.   

    这次应该没问题了
    <html>
    <head>
    <title>javascript读取RSS数据</title>
    <META content="text/html; charset=utf-8" http-equiv=Content-Type />
    </head>
    <body  leftmargin="0" topmargin="0" onload=on_load()> 
    <font><h3 align="center">javascript读取RSS数据</h3></font>
    <br/>  
    <div id="container" >News Loading...</div>
    <script language="JavaScript1.2">
    var xmlDoc;
    function on_load(){
    if (window.ActiveXObject){
    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    }else if (document.implementation && document.implementation.createDocument){
    xmlDoc= document.implementation.createDocument("","doc",null);
    }
    if(typeof xmlDoc!="undefined"){
    var xmlsource="http://rss.xinhuanet.com/rss/it.xml";
    xmlDoc.async="false";
    xmlDoc.load(xmlsource)
    fetchxml();
    }
    }function fetchxml(){
    if (xmlDoc.readyState==4)
    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];
    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]; 
    temp = temp + "<font size=-1><a href=" + link.firstChild.nodeValue+ " target='_bank'>" +title.firstChild.nodeValue+"<br/>"+"</a></font>";
    document.getElementById("container").innerHTML = temp;
    }
    }
    </script>
    </body>
    </html>
      

  3.   

    应该把<SCRIPT></SCRIPT>的内容放到<head></head>之间吧.
    HTML的代码是从上到下顺序执行的.你放到下面在页面加载的时候会报错的.