timer前面加上了var,取消定时器就失效了,这是为什么? 求大神解答,
<script type="text/javascript"> window.onload=function(){ var box1= document.getElementById("box1"); box1.onmouseover=function(){ mvfn1(); } }; var timer = null ; function mvfn1(){ clearInterval(timer); var box1= document.getElementById("box1"); var timer=setInterval(function(){ if (box1.offsetLeft>=0) { clearInterval(timer); } else{ box1.style.left=box1.offsetLeft+1+"px"; } },30); }; </script>