如果这是重复,我会向前道歉。我一直在环顾四周,但没有找到问题的答案。不知道该怎么做。我正在使用XML文件创建一个图像库来上传图像。除了I.E.之外,所有浏览器中都显示了图像。这是我的代码:
XML文件:
<gallery>
<image>
<file>"Gallery_Wedding/W1.jpg"</file>
<thumb>"Gallery_Wedding/Thumbs/TW1.jpg"</thumb>
</image>
<image>
<file>"Gallery_Wedding/W2.jpg"</file>
<thumb>"Gallery_Wedding/Thumbs/TW2.jpg"</thumb>
</image>
</gallery>
解析XML:
function getHttpReq() {
var httpReq=null;
if (window.XMLHttpRequest && !(window.ActiveXObject)) {
try {
httpReq = new XMLHttpRequest();
} catch(e) {
}
}
if (window.ActiveXObject) { // IE
try {
httpReq = new ActiveXObject("Msxml2.XMLHTTP");
alert("it's working!");
} catch(e) {
try {
httpReq = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
}
}
}
return httpReq;
}
function getXmlDoc(httpReq, filename) {
var xmlDoc;
httpReq.open("GET", filename, false /* sync */);
httpReq.send(null);
if (httpReq.status != 404 && httpReq.status!=403)
{
xmlDoc = httpReq.responseXML;
alert("testing");
return xmlDoc;
}else{
return null;
}
}
HTML / Javascript显示:
<script type="text/javascript">
httpReq = getHttpReq();
if (httpReq) {
xmlDoc = getXmlDoc(httpReq, "XML_images_list/wedding_gallery.xml");
if (xmlDoc) {
photos = xmlDoc.getElementsByTagName("image");
for (i=0;i<photos.length;i++)
{
var src=photos[i].getElementsByTagName("file")[0].childNodes[0].nodeValue;
var thumbs=photos[i].getElementsByTagName("thumb")[0].childNodes[0].nodeValue;
var image="image"+i;
document.write("<li><a href="+src+"><img src="+thumbs+"class="+image+"></a></li>");
}
}
}
</script>