<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<img src="img/1000.jpg" alt="" width="400px" height="300px" id="tu">
<button οnclick="begin()">开始</button>
<button οnclick="end()">结束</button>
<script>
var arr =['1000.jpg','1.jpg','2.jpg','3.jpg']
function begin(){
timer=setInterval(change,1);
}
function end(){
clearInterval(timer);//清除定时器
}
function change(){
var i=Math.floor(Math.random()*arr.length);
document.getElementById('tu').src='img/'+arr[i]
}
</script>
</body>
</html>