获取到了Div的ID,怎么是空的呢?
<div id= "NewsInfo ">
<ul id= "newsbox "> <li> loading... </li> </ul>
</div>
var News_Info = document.getElementById( "NewsInfo ");
通过ajax调用,得到responseXML
js解析之后,
var xRows = xmlDoc.getElementsByTagName( 'NewsDetails ');
var Newsdata = " <ul> ";
for(i = 0;i < xRows.length;i++)
{
Newsdata += " <li> <div> <a href= ' " + xRows[i].childNodes[1].firstChild.nodeValue + " ' target = '_blank '> " + xRows[i].childNodes[0].firstChild.nodeValue + " </a> </div> ";
Newsdata += " <div> " + xRows[i].childNodes[2].firstChild.nodeValue + " </div> ";
Newsdata += " <div> " + xRows[i].childNodes[3].firstChild.nodeValue + " </div> ";
Newsdata += " <div> " + xRows[i].childNodes[4].firstChild.nodeValue + " </div> ";
Newsdata += " </div> </li> ";
}
打印出来没有问题
下面News_Info.innerHTML = Newsdata + " </ul> "
就报错了,提示News_Info为空或者不是对象?
怎么解决呢?急急急
------解决方案--------------------,,查查是否有重名NewsInfo的元素
------解决方案--------------------1.检查查查是否有重名NewsInfo的元素
2.试试
function $get(Id)
{
if(document.getElementById(Id))
return document.getElementById(Id);
else
return document.all[Id];
}
$get(NewsInfo).innerHTML =Newsdata + " </ul> ";
------解决方案--------------------var context = NewsInfo;
context.innerHTML = "... ";