1. 程式人生 > >window onload 例項 【2018.11.27】

window onload 例項 【2018.11.27】

<html>
  <head>
    <title>window.onload</title>
    <script type="text/javascript">
       window.onload = function(){
         setInterval(step,1000);
       }
       var num=1;
       function step(){
         if(num < 5){
           num++;
         }else{
           num = 1;
         }
         var dom = document.getElementById("imgId");
         //
         dom.src =  num + '.jpg';
       }
    </script>
  </head>
  <body>
    <img src="1.jpg" width="500" height="500" id="imgId"/>
  </body>
</html>