通过计时器实现图片轮播

<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <style type="text/css">
            #container{width: 524px; height: 190px;margin: 10px auto;border: 3px solid palegreen;}
        </style>
        <script type="text/javascript">
            var index=1;
            window.onload=function(){       
                setInterval("showimage()",1000);
            }
            function showimage(){
                var img=document.getElementsByTagName("img")[0];
                index++;
                if(index>4){
                    index=1;
                }
                img.src="image/ad-0"+index+".jpg";
            }
        </script>
    </head>
    <body>
        <div id="container">
            <img src="image/ad-01.jpg" />
        </div>
    </body>
</html>

猜你喜欢

转载自blog.csdn.net/mhj0201/article/details/82107547
今日推荐