div背景图片自动切换问题

<script  language="javascript" type="text/javascript">
    var images= ["images/2.png", "images/3.png", "images/4.png", "images/5.png"];
    var index = 0;
    function switch_background(){    
    if(index ==images_id.length-1)
    {        
         index = 0;  
    }else{   
         index++;      
    }   
   document.getElementById( "div1" ).style.backgroundImage= "url(" +images[index]+ ")" ;
}
window.onload = function()
{
    setInterval(switch_background, 3000);
} </script>

猜你喜欢

转载自blog.csdn.net/rmnjava/article/details/45338359