<div class="codetitle"> <span><a style="CURSOR: pointer" data="11562" class="copybut" id="copybut11562" onclick="doCopy('code11562')"><u>複製代碼</u></a></span> 代碼如下:</div> <div class="codebody" id="code11562"> <br>//W3C/1. Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br> <br> <br><title></title> <br><script type="text/javascript"> <BR>var numb = 0; <BR>var imgnumb = 1; <BR> function showimg() { <BR>//兩張圖片切換方法1 /*numb ; <BR>if (numb % 2 == 0) { <BR>document.getElementById('img1').setAttribute('src' , 'images/1.jpg'); <BR>} <BR>else { <BR>document.getElementById('img1').setAttribute('src', 'images/2.jpg'); <BR>} */ <BR>//兩張圖片切換方法2 /*if (numb == 0) { <BR>document.getElementById('img1').setAttribute('src', 'images/2.jpg'); <BR>numb = 1; <BR>} <BR>else { <BR>document.getElementById('img1').setAttribute('src', 'images/1.jpg'); <BR>numb = 0; <BR>}*/ <BR>} <BR>/圖片輪替/多張function imgfor() { <BR>imgnumb ; <BR>document.getElementById('img1').setAttribute('src', 'images/ ' imgnumb '.jpg'); <BR>if (imgnumb == 9) { <BR>imgnumb = 0; <BR>} <BR>} <BR>var clearid; <BR>function clearfun() { <BR>clearInterval(clearid); <BR>} <BR>clearid=setInterval(imgfor, 1000); <BR></script> <br> <br> <br><img alt=" " id="img1" class="style1" src="images/1.jpg" style="max-width:90%" height="500px"> <br><input type="button" value="兩張圖片切換" onclick="showimg();"> <br><br> <br><input type="button" value="多張圖片輪換" onclick="imgfor();;"> <br> <br><input type="button" value="結束執行" onclick="clearfun();"> <br> <br> <br> </div>