javascript—广告弹窗

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script type="text/javascript">
            var time;
            window.onload = function(){
                time = setTimeout("show()",2000);//设置两秒后开始调用show方法,并用time记住setTimeout的返回值
            }
            function show(){
                var img1 = document.getElementById("img1");
                img1.style.display = "block";//将图片设置为显示
                clearTimeout(time);//清除原来的setTimeout的设置,可以不写,因为下面有重新赋值
                time = window.setTimeout("hide()",2000); //两秒后调用hide()方法隐藏图片,并将time重新赋值。   
            }
            function hide(){
                var img1 = document.getElementById("img1");
                img1.style.display = "none";//将图片设置为隐藏
                clearTimeout(time);//可有可无
                time = window.setTimeout("show()",2000);//两秒后调用show()方法显示图片,并将time重新赋值
            }
        </script>
    </head>
    <body>
        <img src="img3.jpg" id="img1" id="img1">
    </body>
</html>
posted @ 2019-12-27 12:10  wwww2  阅读(180)  评论(0编辑  收藏  举报