类似轮播图
<input type="button" id="btn1" value="开始" />
<input type="button" id="btn2" value="暂停" />
<div id="yanse" style="width: 200px; height: 200px;border: dashed;">
</div>
<script type="text/javascript">
var obtn1=document.getElementById("btn1")
var obtn2=document.getElementById("btn2")
var oyanse=document.getElementById("yanse")
var timer=null
var n=0
var arr=["red","green","yellow","bule"]
obtn1.onclick=function () {
timer=setInterval(shijian,1000)
}
function shijian () {
clearInterval(timer)
oyanse.style.backgroundColor=arr[n]
n++
n=n%arr.length
}
obtn2.onclick=function () {
clearInterval(timer)
}
</script>