日期:2014-05-16  浏览次数:20440 次

为什么setTimeout函数不起作用
想让div在页面加载完毕时移动,但总是报错,提示to_move未定义,十分不解,大家帮忙看看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload=function (){
 var oMove=document.getElementById("move");
function to_move()
{
 
  var x=oMove.offsetLeft;  
  x=x+1; 
  oMove.style.left=x+"px";
 setTimeout("to_move",100);
}
to_move();
};
</script>
</head>
<body>
<div id="move" style="width:100px; height:100px; background-color:red; position:absolute; left:1px; top:1px"></div>
</body>
</html>

------解决方案--------------------
探讨

setTimeout("to_move()",100);
或者setTimeout(to_move,100);

------解决方案--------------------
setTimeout("tomove()",100);
//or
setTimeout(tomove,100);