Home > Web Front-end > JS Tutorial > body text

Javascript xml implements simple image rotation (only supports IE)_javascript skills

WBOY
Release: 2016-05-16 17:45:48
Original
1107 people have browsed it

I've been bored recently. I saw that many websites have automatic rotation of advertisements. I tried to write an image rotation myself. The code and function are very simple. It only supports IE, and FF needs to add some stuff.

xml file: test.xml

Copy code The code is as follows:

< ;?xml version="1.0" encoding="gb2312"?>

http://www.163.com< /neteasy>
http://www.sina.com.cn
http://www.sohu.com


HTML
Copy code The code is as follows:



javascript
Copy code The code is as follows:

<script> <br>//Image rotation<br>var a = 0; <br>var xmlDoc; <br>var image1 = document.getElementById ("image1"); <br>function loadxml(path) <br>{ <br>xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); <br>xmlDoc.async = false; <br>xmlDoc.load(path ); <br>} <br>loadxml("test.xml"); <br>function changeImage() <br>{ <br>var ad = xmlDoc.getElementsByTagName("ad")[0]; <br> if(a == ad.childNodes.length) <br>{ <br>a=0; <br>} <br>var path = ad.childNodes[a].getAttribute("path"); <br>var url = ad.childNodes[a].text; <br>image1.src = path; <br>image1.onclick = function(){window.open(url);}; <br>a =1; <br> setTimeout("changeImage()",1000); <br>} <br>changeImage(); <br></script>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!