28,391
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<script>
var xmlHttp;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
function startRequest()
{
createXMLHttpRequest();
try
{
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET", "data.xml", true);
xmlHttp.send(null);
}
catch(exception)
{
alert("xmlHttp Fail");
}
}
function handleStateChange()
{
if(xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200 || xmlHttp.status == 0)
{
var root = xmlHttp.responseXML.documentElement;
var links = root.getElementsByTagName("link");
var marquee1 = document.getElementById("marquee1");
for(var i=0; i<links.length; i++)
{
var link = document.createElement("a");
link.href = links[i].getAttribute("href")
link.innerHTML = links[i].getAttribute("text")
link.style.fontWeight = "bold";
marquee1.appendChild(link);
var br = document.createElement("br");
marquee1.appendChild(br);
}
}
}
}
window.onload=startRequest;
</script>
</head>
<body>
<marquee id="marquee1" width="100" height="120" behavior="alternate" scrolldelay="300" direction="up" bgcolor="DDEEFF">
</marquee>
</body>
</html>
<?xml version="1.0" encoding="GB2312"?>
<root>
<link href="http://www.hao123.com" text="Hao123"></link>
<link href="http://www.baidu.com" text="Baidu"></link>
<link href="http://www.google.cn" text="Google"></link>
</root>