我有这段代码。它收到错误 document.getElementById('foo') 为空。请帮助解决这个问题。
<script>
function doMove() {
var foo=document.getElementById('foo');
foo.style.left = (foo.style.left+10)+'px'; // pseudo-property code: Move right by 10px
setTimeout(doMove(),20); // call doMove() in 20 msec
}
doMove();
</script>
</head>
<body>
<div id="foo" style="width:10px;">a</div>
</body>
</html>