0

我已经.txt使用表格数据控件从文件中读取数据,但我想做的是在时间间隔内更改数据(最近的数据将被下一个数据替换)。

我想过使用.moveNext()和延迟,但似乎我把延迟实现弄错了。

var rs2 = CHAR.recordset;
var delay;
function set()
{
    if(!rs2.EOF && !rs2.BOF)
    {
        var temp = "Characters/"+rs2(1);
        document.getElementById('txt').innerHTML = rs2(0);
        document.getElementById('pic').src = temp;     
    }
}
function begin()
{
    rs2.moveFirst();
    set();  
    delay = setTimeout(move(2), 1000);
}
function move(idx)
{
    switch(idx)
    {
        case 1: if (!rs2.BOF) rs2.movePrevious();
                else rs2.moveLast();
                break;
        case 2: if (!rs2.EOF) rs2.moveNext();
                else rs2.moveFirst();
                break;
    }
    set();

    if(delay)
        clearTimeout(delay);
    delay = setTimeout(move(2), 1000);
}

执行时delay(我认为),脚本变得无响应。我认为它发生是因为它进行了太多递归,但我不知道如何解决它。

4

1 回答 1

0

i make my another function just for this and i think it's more convenient. it can help move() to focus on its own job(which will be called later) while doing the recursive on the right interval.

here's the function:

function automove()
{               
    if (!rs2.BOF) rs2.movePrevious();
    else rs2.moveLast();
    set();

    if(delay)
        clearTimeout(delay);
    delay = setTimeout(automove, 2000);
}
于 2012-04-18T02:55:46.297 回答