楼主试试这个看看
<img id="images" >
<script>
function getImg()
{
   document.all.images.src = "img/"+parseInt(Math.random()*(5))+".gif";
    if(document.all.images.clientWidth>150 && document.all.images.clientHeight>100)
      document.all.images.src = "img/'+parseInt(Math.random()*(5))+'.gif";
}
setInterval("getImg()",3000); 
</script>