标签:图片浏览 script list img als element type length listen
<html> <head> <title></title> <head> <script> window.onload=function(){ var imgs=new Array("a.jpg","b.jpg","c.jpg"); var foot=1; //获取按钮 var preButton=document.getElementById("preButton"); var nextButton=document.getElementById("nextButton"); //获取img var myimg=document.getElementById("myimg"); //为按钮添加事件监听 preButton.addEventListener("click",function(){ if(foot<=0){ foot=imgs.length-1; } myimg.src="d:/picture/"+imgs[foot--]; //alert(myimg.src); },false); nextButton.addEventListener("click",function(){ if(foot>=imgs.length){ foot=0; } myimg.src="d:/picture/"+imgs[foot++]; // alert(myimg.src); },false); } </script> <body> <span id="myspan"> <img id="myimg" src="d:/picture/a.jpg" height="60%" /> </span> <div> <button type="button" id="preButton">上一张</button> <button type="button" id="nextButton">下一张</button> <div> </body> </html>
标签:图片浏览 script list img als element type length listen
原文地址:http://www.cnblogs.com/yuefeng123/p/7501242.html