当我尝试运行该程序时,我在 Firefox 中收到错误消息:
moveDate 在第 41 行未定义
(参考线window.setTimeout("moveDate()",100);
.
任何想法为什么?我认为递归函数能够定义自己,然后调用自己。
function monthScroller(){
document.getElementById("month").style.visibility = "visible";
var x = 0;
var y = 0;
var dest_x = window.innerWidth/2;
var dest_y = window.innerHeight/2;
var interval = 1;
function moveDate() {
if(x<dest_x){ x = x + interval;}
if(y<dest_y){ y = y + interval;}
document.getElementById("month").style.top = y+"px";
document.getElementById("month").style.left = x+"px";
if ((x+interval < dest_x) && (y+interval < dest_y)) {
window.setTimeout("moveDate()",100);
}
else{
name();
}
}
moveDate();
}