日期:2014-05-18  浏览次数:20423 次

恼人的问题,头疼很久了!各位大虾帮个忙~
我写了个js代码:
如下:
var   oDoc   =   new   ActiveXObject( "Msxml2.DOMDocument ");
oDoc.async   =   false;
function   RenderHtml(xmlPath,selectNode_Title,selectNode_Link,objShow,totalNum,titleNum)
{
   
      var   html   =   " ";  
      oDoc.load(xmlPath);  
      oNodes   =   oDoc.selectNodes(selectNode_Title);
      href   =   oDoc.selectNodes(selectNode_Link);
      var   num   =   totalNum <oNodes.length   ?   totalNum   :     oNodes.length;
      var   page=oNodes.length/totalNum;
      for(var   i=0;i <num;i++)
      {
                        a=oNodes[i].text;
                        c=a.substr(0,titleNum);
      html   +=   " <a   href=\ " "   +   href[i].text   +   "\ "   target=_blank   title=\ " "+c+ "\ "> ·领导: "   +c+   " </a> <br/> \n ";
      }
objShow.innerHTML=html
}
RenderHtml( "xml/news/xylw/newsxml.xml ", "/news/xylw/item/title ", "/news/xylw/item/link ",rrrr,10,10);
RenderHtml( "xml/news/xylw/newsxml.xml ", "/news/xylw/item/title ", "/news/xylw/item/link ",rrrr2,10,10);
RenderHtml( "xml/news/xylw/newsxml.xml ", "/news/xylw/item/title ", "/news/xylw/item/link ",rrrr3,10,10);
RenderHtml( "xml/news/xylw/newsxml.xml ", "/news/xylw/item/title ", "/news/xylw/item/link ",rrrr4,10,10);
RenderHtml( "xml/news/xylw/newsxml.xml ", "/news/xylw/item/title ", "/news/xylw/item/link ",rrrr5,10,10);

------解决方案--------------------
var oDoc = new ActiveXObject( "Msxml2.DOMDocument ");
oDoc.async = false;
function RenderHtml(xmlPath,selectNode_Title,selectNode_Link,objShow,totalNum,titleNum)
{
var div = document.getElementById(objShow);
if (div==null)
return;
var html = " ";
oDoc.load(xmlPath);
oNodes = oDoc.selectNodes(selectNode_Title);
href = oDoc.selectNodes(selectNode_Link);
var num = totalNum <oNodes.length ? totalNum : oNodes.length;
var page=oNodes.length/totalNum;
for(var i=0;i <num;i++)
{
a=oNodes[i].text;
c=a.substr(0,titleNum);
html += " <a href=\ " " + href[i].text + "\ " target=_blank title=\ " "+c+ "\ "> ·领导: "

+c+ " </a> <br/> \n ";
}
div.innerHTML=html;
}