代码:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script> function init() { setTimeout("showAD()", 3000); } function showAD() { //首先要获取要操作的img var img = document.getElementById("img"); //显示广告 img.style.display = "block"; //再开启定时器,关闭广告 setTimeout("hideAD()", 3000); } function hideAD() { //首先要获取要操作的img var img = document.getElementById("img"); //隐藏广告 img.style.display = "none"; } </script> </head> <body onload="init()"> <img id="img" src="https://www.cnblogs.com/images/cnblogs_com/believepd/1348456/t_ad.jpg" width="100%" style="display: none;"/> </body> </html>