I was bored and I hadn't built one of these before. Here is what I came up with: http://jsfiddle.net/grantk/pHdAN/<div id="images" style="height:300px;"> <img src="http://www.livehacking.com/web/wp-content/uploads/2012/08/chrome-logo-1301044215-300x300.jpg" /> <img src="http://upload.wikimedia.org/wikipedia/commons/e/e7/Mozilla_Firefox_3.5_logo_256.png" /> <img src="http://html5doctor.com/wp-content/uploads/2011/01/HTML5_Logo_256.png" /></div><a id="prev" href="#">Prev</a> <a id="next" href="#">Next</a><script>var imgArr = document.getElementById('images').getElementsByTagName('img');//Hide all images except firstfor(var i=1; i<imgArr.length; i++){ imgArr[i].style.display = "none";}i=0;document.getElementById('prev').onclick = function(){ if(i===0){ imgArr[i].style.display = "none"; i=imgArr.length-1; imgArr[i].style.display = ""; } else{ imgArr[i].style.display = "none"; i--; imgArr[i].style.display = ""; }}document.getElementById('next').onclick = function(){ if(i===imgArr.length-1){ imgArr[i].style.display = "none"; i=0; imgArr[i].style.display = ""; } else{ imgArr[i].style.display = "none"; i++; imgArr[i].style.display = ""; }}</script> 这篇关于使用JavaScript的图像数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-27 03:39