主题:请帮忙看看为什么取不到节点值?
红色标记的那两行,老是提示缺少对象:
function showList(xmlDoc){
[color=FF0000] var currentPage = xmlDoc.childNodes[0].firstChild.firstChild.nodeValue;
var total = xmlDoc.childNodes[0].firstChild.nextSibling.firstChild.nodeValue;[/color]
if(currentPage>1){
document.getElementById('lastPage').innerHTML='<a href="javascript:void(0)" onclick=queryPage('+(parseInt(currentPage)-1)+')><上一页</a>';
}else{
document.getElementById('lastPage').innerHTML='';
}
if(currentPage!=total){
document.getElementById('nextPage').innerHTML='<a href="javascript:void(0)" onclick=queryPage('+(parseInt(currentPage)+1)+')>下一页></a>';
}else{
document.getElementById('nextPage').innerHTML='';
}
document.getElementById('currentPage').innerHTML='当前页:'+currentPage;
document.getElementById('total').innerHTML='总页数:'+total;
var lists = xmlDoc.childNodes[0].childNodes[2].childNodes;
var tbody = document.getElementsByTagName('tbody')[0];
tbody.innerHTML='<tr><th>标题</th><th>摘要</th></tr>';
for(i=0;i<lists.length;i++){
var title = lists[i].firstChild.firstChild.nodeValue;
var abstract = lists[i].firstChild.nextSibling.firstChild.nodeValue;
appendRow(title,abstract);
}
}
相对应的XML文件为:
Content-Type: text/xml;charset=gb2312
<content>
<currentpage>1</currentpage><total>4</total>
<lists>
<list>
<title>1001</title><abstract>成员一</abstract>
<title>1002</title><abstract>成员二</abstract>
</list>
</lists>
</content>
function showList(xmlDoc){
[color=FF0000] var currentPage = xmlDoc.childNodes[0].firstChild.firstChild.nodeValue;
var total = xmlDoc.childNodes[0].firstChild.nextSibling.firstChild.nodeValue;[/color]
if(currentPage>1){
document.getElementById('lastPage').innerHTML='<a href="javascript:void(0)" onclick=queryPage('+(parseInt(currentPage)-1)+')><上一页</a>';
}else{
document.getElementById('lastPage').innerHTML='';
}
if(currentPage!=total){
document.getElementById('nextPage').innerHTML='<a href="javascript:void(0)" onclick=queryPage('+(parseInt(currentPage)+1)+')>下一页></a>';
}else{
document.getElementById('nextPage').innerHTML='';
}
document.getElementById('currentPage').innerHTML='当前页:'+currentPage;
document.getElementById('total').innerHTML='总页数:'+total;
var lists = xmlDoc.childNodes[0].childNodes[2].childNodes;
var tbody = document.getElementsByTagName('tbody')[0];
tbody.innerHTML='<tr><th>标题</th><th>摘要</th></tr>';
for(i=0;i<lists.length;i++){
var title = lists[i].firstChild.firstChild.nodeValue;
var abstract = lists[i].firstChild.nextSibling.firstChild.nodeValue;
appendRow(title,abstract);
}
}
相对应的XML文件为:
Content-Type: text/xml;charset=gb2312
<content>
<currentpage>1</currentpage><total>4</total>
<lists>
<list>
<title>1001</title><abstract>成员一</abstract>
<title>1002</title><abstract>成员二</abstract>
</list>
</lists>
</content>