我编写了这个函数来将 DIV 从右上角飞到左下角:
var myObj;
function infly() {
myObj=document.getElementById('mydiv');
myObj.style.right='0px';
myObj.style.top='0px';
}
function flyer() {
var x=parseInt(myObj.style.right);
var y=parseInt(myObj.style.top);
x+=1;
y+=1;
myObj.style.right=x+'px';
myObj.style.top=y+'px';
}
function repeat()
{
setTimeout(flyer,5000)
}
HTML 代码是:
<body onLoad="infly()">
<div id="mydiv">
</div>
<a href="" onClick="javascript:repeat()">Fly</a>
...
..
.
但是repeat
功能不起作用。当我在每次点击中删除此功能时,我的 DIV 都会正确飞行。
我尝试使用 setInterval('fly();', 10);
但没有成功。
感谢您的帮助。
<小时/>更新:
我编辑了代码并更正了repeat
功能,但仍然不起作用。
最佳答案
使用
setTimeout(fly,5000)
而不是
setTimeout("fly()","5000()")
关于JavaScript : repeat function not work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8653849/