window.οnlοad=function(){
var obox=document.getElementById('box');var obtn=document.getElementById('btn');
var timer=null;//定时器的变量,存储空间,条件判断避免重复,开启定时器之前先关闭
function move(){
if(obox.offsetLeft>=300){//移动到300px时停止
clearInterval(timer);
}
else{
obox.style.left=obox.offsetLeft+10+'px';
}
}
obtn.οnclick=function(){
clearInterval(timer);
timer=setInterval(move,50);
}
}