<script>
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","Default.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var management=xmlDoc.getElementsByTagName("Management");
document.write("<tr><td>");
document.write(management[i].getElementsByTagName("RepresentativeName")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
</script>
我在其他浏览器中使用xml元素没有任何价值。但即告诉我错误,并没有呈现UI
答案 0 :(得分:1)
您需要在将条件写入文档之前添加if条件。
尝试这样的代码
<script>
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","Default.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var management=xmlDoc.getElementsByTagName("Management");
document.write("<tr><td>");
if(management[i].getElementsByTagName("RepresentativeName")[0].childNodes[0]){
document.write(management[i].getElementsByTagName("RepresentativeName")[0].childNodes[0].nodeValue);
}else{
document.write('');
}
document.write("</td></tr>");
</script>