javascript定时变换图片实例代码

复制代码 代码如下:

  <html>

  <head>

  <meta http-equiv=Content-Type content="text/html;charset=utf-8">

  <script>

  y=1;

  function imgs()

  {

  var myImg=document.getElementsByTagName("img")[0];

  myImg.src=y+".jpg";

  if(y==2)y=1;

  else y++;

  }

  </script>

  </head>

  <body onload="setInterval(imgs,1000);">

  <div align="center">

  <img src="1.jpg">

  </div>

  </body>

  </html>