<html>
<head>
<script language="JavaScript">
function GetRnd(min,max){ 
   var num = Math.floor(Math.random() * (max - min + 1) + min);
 document.getElementById("imgContainer").innerHTML="<img src='./"+num+".jpg'/>";

             

function start(){
setInterval("GetRnd(1,7)",500);
}

</script>
</head>

<body>
        <div id="imgContainer"></div>
<input type="button" value="随即选择" onClick="start()"/>

</body>
</html>

解决方案 »

  1.   

    不要用start做函数名,换一个
      

  2.   

    果然是这样 谢谢再请问怎么让我写的这个随机图片停下呢 
    我又写了一个按钮调用了clearInterval()为什么不行呢<input type="button" value="停止" onClick="stop()"/>function stop(){
    clearInterval("GetRnd(1,7)",500);
    }
      

  3.   

    解决了 function maki(){
    sid=setInterval("GetRnd(1,7)",300);
    }

    function stop(){
    clearInterval(sid);
    }
      

  4.   

    最后调整 因为图片总是更着 按钮一起动 所以又改动一句
    <div id="imgContainer" style="overflow:hidden;width:100px;height:100px"></div>
    通过添加一个大容器的样式进行调整。