XMLDOM 创建(二)

来源:互联网 发布:嘉实优化红利 天天基金 编辑:程序博客网 时间:2024/04/29 11:02
script language="网页特效" type="text/javascript">
var xmldoc;
function showcurcity()
{
if(window.activexobject)
{
xmldoc=new activexobject("microsoft.xmldom");
xmldoc.async="false"
xmldoc.load("olycity.xml");
getvalue();
}
else if(document.implementation && document.implementation.createdocument)
{
xmldoc=document.implementation.createdocument("", "root", null);
xmldoc.load('olycity.xml');
xmldoc.onload=getvalueff;
}
else
{
return null;
}
}
function getvalue()
{
var nodes=xmldoc.documentelement.childnodes;
var now=new date();
for(i=0;i<nodes.length;i++){
var value=nodes.item(i).childnodes.item(0).text ;
if(value==now.tolocaledatestring())
{
window.document.getelementbyid('curcity').innertext=nodes.item(i).childnodes.item(1).text;
window.document.getelementbyid('curcity').href =nodes.item(i).childnodes.item(2).text;
}
}
}
function getvalueff(){
var ccode=xmldoc.getelementsbytagname("date");
var now = new date();
var nowvalue=now.getfullyear()+'年'+(now.getmonth()+1)+'月'+now.getdate()+'日';
for(i=0;i<ccode.length;i++)
{
var value=ccode[i].childnodes[0].nodevalue;
if(value==nowvalue)
{
window.document.getelementbyid('curcity').href =xmldoc.getelementsbytagname("url")[i].childnodes[0].nodevalue;;
window.document.getelementbyid('curcity').childnodes[0].nodevalue=xmldoc.getelementsbytagname("city")[i].childnodes[0].nodevalue;
}
}
}
setinterval(showcurcity,1000);
</script>
更多详细内容请查看:http://www.111cn.net/wy/js-ajax/js-xml.htm
原创粉丝点击