Posted in Javascript onDecember 23, 2012
最近无聊,看着许多网站都有广告自动轮换,自己试着写了一个图片轮换,代码和功能都很简单,只支持IE的,FF的还要加些东东.
xml文件:test.xml
<?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>
HTML
<img id="image1" name="image1" src="image/64_jpg.jpg" style="cursor:hand; width: 110px; height: 103px;"/>
javascript
<script> //图片轮换 var a = 0 ; var xmlDoc; var image1 = document.getElementById("image1"); function loadxml(path) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = false; xmlDoc.load(path); } loadxml("test.xml"); function changeImage() { var ad = xmlDoc.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>
javascript+xml实现简单图片轮换(只支持IE)
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@