Posted in Javascript onApril 16, 2013
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script type="text/javascript"> var numb = 0; var imgnumb = 1; function showimg() { //两张图片切换方法1 /*numb++; if (numb % 2 == 0) { document.getElementById('img1').setAttribute('src', 'images/1.jpg'); } else { document.getElementById('img1').setAttribute('src', 'images/2.jpg'); }*/ //两张图片切换方法2 /*if (numb == 0) { document.getElementById('img1').setAttribute('src', 'images/2.jpg'); numb = 1; } else { document.getElementById('img1').setAttribute('src', 'images/1.jpg'); numb = 0; }*/ } /图片轮换/多张 function imgfor() { imgnumb++; document.getElementById('img1').setAttribute('src', 'images/' + imgnumb + '.jpg'); if (imgnumb == 9) { imgnumb = 0; } } var clearid; function clearfun() { clearInterval(clearid); } clearid=setInterval(imgfor, 1000); </script> </head> <body> <img alt="" id="img1" class="style1" src="images/1.jpg" width="500px" height="500px" /> <input type="button" value="两张图片切换" onclick="showimg();" /> <br /> <input type="button" value="多张图片轮换" onclick="imgfor();;" /> <br /> <input type="button" value="结束执行" onclick="clearfun();" /> </body> </html>
js实现图片轮换效果代码
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@