dom在IE上好使,在firefox上不好使
<img id="image1" name="image1" src="image/64_jpg.jpg" style="cursor:hand; width: 110px; height: 103px;"/>
<script>
function GetXMLDocument()
{
var xmlDoc = null;
if(document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("","",null);
}
else if(typeof ActiveXObject != "undefined")
{
var msXmlAx = null;
try
{
msXmlAx = new ActiveXObject("Msxml2.DOMDocument");
}
catch(e)
{
msXmlAx = new ActiveXObject("Msxml.DOMDocument");
}
xmlDoc = msXmlAx;
}
if( xmlDoc==null || typeof xmlDoc.load=="undefined")
{
xmldoc=null;
}
return xmlDoc;
}
//图片轮换
var a = 0 ;
var xDoc = GetXMLDocument();
xDoc.async = false;
xDoc.load("test.xml");
var image1 = document.getElementById("image1");
function changeImage()
{
var ad = xDoc.getElementsByTagName("ad")[0];
if(a == ad.childNodes.length)
{
a=0;
}
var path = ad.childNodes[a].getAttribute("path");
var url = ad.childNodes[a].text;
image1.src = path;
image1.onclick = function(){window.open(url);};
a+=1;
setTimeout("changeImage()",1000);
}
changeImage();
</script>
经过调试,能得到ad 节点,得不到childNodes[a]节点,而且ad.childNodes.length=7
求解~
<?xml version="1.0" encoding="gb2312"?>
<ad>
<neteasy path="image/64_jpg.jpg">http://www.163.com</neteasy>
<sina path="image/lining.jpg">http://www.sina.com.cn</sina>
<sohu path="image/Image00045.jpg">http://www.sohu.com</sohu>
</ad>