我想问而不是使用document.write,如何使用innerHTML将XML信息写入div?我尝试使用 document.getElementById("box").innerHTML 但我不确定如何。
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc(dname){
if (window.XMLHttpRequest){
xhttp=new XMLHttpRequest();
}else{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}
</script>
<script>
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("title");
for (i=0;i<x.length;i++)
{
document.write(x[i].childNodes[0].nodeValue);
document.write("<br>");
//instead of using document.write how do I use innerHTML?
//this is the method i tried:
//txt = document.write(x[i].childNodes[0].nodeValue);
//document.getElementById("box").innerHTML = txt;
//it is not working, can anyone advice?
}
</script>
</head>
<body>
<div id="box"></div>
</body>
</html>