JS 實現定時操作 隱藏顯示圖片(setInterval() clearInterval())
阿新 • • 發佈:2018-10-31
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script> function init(){ time = setInterval("showAd()",3000); } function showAd(){ document.getElementById("img1").style.display="block"; //清除顯示圖片的定時操作 clearInterval(time); time = setInterval("hiddenAd()",3000); } function hiddenAd(){ document.getElementById("img1").style.display="none"; //清除隱藏圖片的定時操作 clearInterval(time); } </script> </head> <body onload="init()"> <p>111</p> <img src="img/ad.jpg" style="display: none;" id="img1"/> <p>222</p> </body> </html>