日期:2014-05-16  浏览次数:20387 次

js 简单图片切换

?

 <div id="pic">
    <img src="http://dl.iteye.com/upload/picture/pic/109739/28faf72f-a866-3151-8b51-3d3f4cc6a095.png"/>
    <img src="http://dl.iteye.com/upload/picture/pic/109751/c027ba99-2889-3365-8dd1-47f65991b47d.png" style="display:none"/>
    <img src="http://dl.iteye.com/upload/picture/pic/109749/abfeb883-1caf-3c00-96e7-6594930c0ae5.png" style="display:none"/>
    <img src="http://dl.iteye.com/upload/picture/pic/109753/77a99704-9402-3f97-b0f1-d0cae74d8772.png" style="display:none"/>
    <script type="text/javascript">
    setInterval(function(){ var l = document.getElementById('pic').getElementsByTagName('img'); for(i=0; i<l.length; i++) { if(l[i].style.display=='none') continue; l[i].style.display = 'none'; l[(i+1)%l.length].style.display = 'inline'; break; } }, 2000);
   </script>
 </div>

?定时切换显示div(#pic)内的图片。

?