xml結構如下
var Now = new Date();
var Min = Now.getSec
//讀取秒數,根據奇偶隨機輪換,當然也可以改變此處演算法增加xml節點數
{
i = 1;
}
else
{ i = 0; }
var url = "xml/ads.xml";
String.prototype.Trim = function() {
return this.replace(/(^s*)|(s*$ )/g, "");
}
var xmlDoc;
//判斷是否為Firefox或IE
var moz = (typeof document.implementation != 'undefined') & (typeof document.implementation != 'undefined') && (typeof. .implementation.createDocument != 'undefined');
var ie = (typeof window.ActiveXObject != 'undefined');
function importXML(file) {
if (moz) 🎜>xmlDoc = document.implementation.createDocument("", "doc", null);
//建立FIREFOX下XML文件物件
}
else if (ie))
ActiveXObject("MSXML2.DOMDocument.3.0");
xmlDoc.async = false;
while( xmlDoc.readyState != 4) {};
//建立IE下XML文件物件
}
}
}
}
}
}
xmlDoc.load(file);
}importXML(url);//載入xml
function updatetupiandizhi()
{
if (moz)
{
var
if (moz)
{
var ad = xmlDoc.getElementsByTagName("ad")[0];
var tupian;
var _tupian = ad.getElementsByTagName("tupian")[i].firstChild.nodecon;
if (_tupian) = _tupian.Trim();
//得到tupian,dizhi節點下的值
var dizhi;
var _dizhi=ad.getElementsByTagName("dizhi")[Chii].nohio")[ >if(_dizhi) dizhi = _dizhi.Trim();
document.getElementById('tupian').href = tupian;
document.getElementById('dizhi').src = dizhio/o🎠實作輪換
} else if (ie)
{var src = xmlDoc.documentElement.selectNodes("tupian");
var href = xmlDoc.documentElement.selectNodes("dizhi"); /得到tupian,dizhi節點下的值
document.getElementById("dizhi").href = href(i).text;
document.getElementById("tupian").src = src(i).text ;
//實現輪換
}}