<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title> Untitled Document </title>
<body>
<input type= "button" value= "Change Background"/>
<input type= "button" value= "Stop"/>
<script>
var abtn = document.getelementsbytagname (' input ');
var arrurl = [' img/1.jpg ', ' img/2.jpg ', ' img/3.jpg ', ' img/4.jpg '];
var num = 0;
var timer = null;
var obody = document.body;
Abtn[0].onclick = function () {
Clearinterval (timer); null, undefined
The timer is controlled by the user, must be closed after the open, to prevent the user hand speed too fast continuous click
Timer = setinterval (function () {
oBody.style.background = ' url (' + arrurl[num] + ') ';
num++;
Num%=arrurl.length;
}, 1000);
};
Abtn[1].onclick = function () {
Clearinterval (timer);
};
oBody.style.background = ' url (' + arrurl[num] + ') ';
</script>
</body>
js-Timer Change background