<script>
var oTime = null; //为何不能放在函数体内?
function move(){
//var oTime = null ????
var oDiv = document.getElementById('div1');
clearInterval(oTime);
oTime = setInterval(function(){
//先判断 如果左边坐标大于600 停止运动
if(oDiv.offsetLeft >=600){
clearInterval(oTime);
}
//否则 左边坐标+10;
else
{
var speed = 1;
oDiv.style.left = oDiv.offsetLeft+speed+'px';
} },30);
}</script>
var oTime = null; //为何不能放在函数体内?
function move(){
//var oTime = null ????
var oDiv = document.getElementById('div1');
clearInterval(oTime);
oTime = setInterval(function(){
//先判断 如果左边坐标大于600 停止运动
if(oDiv.offsetLeft >=600){
clearInterval(oTime);
}
//否则 左边坐标+10;
else
{
var speed = 1;
oDiv.style.left = oDiv.offsetLeft+speed+'px';
} },30);
}</script>
clearInterval(oTime);传参的是新的oTime,值是null,当然不能停止上一个函数内创建的定时器了