标签:value ack head body element round 暂停 style nload
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>定时器---换图片背景</title>
<script type="text/javascript" src="http://cdn.gbtags.com/jquery/1.11.1/jquery.min.js"></script>
<style type="text/css">
</style>
</head>
<body>
<input type="button" value="换背景">
<input type="button" value="暂停">
</body>
</html>
<script type="text/javascript">
window.onload=function (){
var oBtn=document.getElementsByTagName(‘input‘);
var arrUrl=[‘img/1.jpg‘,‘img/2.jpg‘,‘img/3.jpg‘,‘img/4.jpg‘];
var oBody=document.body;
var num=0;
var timer=null;
oBtn[0].onclick=function(){
clearInterval(timer);
timer=setInterval(function(){
oBody.style.background=‘url(‘+arrUrl[num]+‘)‘;
num++;
num%=arrUrl.length;
},100);
}
oBtn[1].onclick=function(){
clearInterval(timer);
}
}
</script>
标签:value ack head body element round 暂停 style nload
原文地址:http://www.cnblogs.com/ll-taj/p/6587271.html