本帖最后由 zzheaven 于 2012-03-22 22:15:56 编辑

解决方案 »

  1.   

    我需要多次调用不同新闻源的RSS(XML)来完成。
      

  2.   


    //Container for ticker. Modify its STYLE attribute to customize style:
    var tickercontainer=''var xmlsource="http://rss.sina.com.cn/news/marquee/ddt.xml";
    //var xmlsource="http://news.baidu.com/n?cmd=1&class=enternews&tn=rss";
    var root;
    var title;
    var link; 
    var items;
    var item;
    var images;
    var image;
    var description;
    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")
    {
      //document.write(tickercontainer)
    //xmlDoc.async=true;
      xmlDoc.load(xmlsource)//加载xml文件(xml的地址)
    }  
    function fetchxml()
    {
      if (xmlDoc.readyState==4) //状态为4时候才执行
       output()
      else
       setTimeout("fetchxml()",2000)
    }
    function output()
    {  
      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++)
      for(i=0;i<=11;i++)
      {
       item=items[i];
       title=item.getElementsByTagName("title")[0]; 
       link=item.getElementsByTagName("link")[0];
       description=item.getElementsByTagName("description")[0];
       temp = temp + "<font size=-1><a href=" + link.firstChild.nodeValue+ " target='_bank'>" + title.firstChild.nodeValue +"</a></font><br><br>";
       //temp = temp +"<font size=-1>" + description.firstChild.nodeValue + "</font><br><br>";
       document.getElementById("container").innerHTML = temp;
      }
      }
    if (window.ActiveXObject)
      {
    fetchxml()
    }
    else if (typeof xmlDoc!="undefined")
    {
    alert("sth is wrong!")
    }

    这个是JS代码,需要从页面中调用
      

  3.   

    就仅仅写了上面的JS代码,然后在htm页面中调用,有问题吗?
      

  4.   

    一个页面通过多次调用这个js文件,然后只修改url(xmlsource)可以将内容都显示吗?怎么没有大牛回答,俺是菜鸟