0

JS小提琴代码

var id = 1;
var lala = new Array(
    'Hello World',
    'This is my new and fancy console!',
    'See how its typing?',
    'Isn\'t that cool ? ',
    'Try it out for yourself!');
lala.each(function (line) {
    id++;
    fullID = 'Div' + id;
    new Element('p', {
        'id': fullID
    }).inject($(document.body));
    texttype(fullID, line, 100, 100);
});

我试图在每个循环中调用 MooTools 中的一个方法,但问题是由于 javascripts 的性质,所有方法调用都是在 aprox 处调用的。同时。我该如何防止这种情况发生?我需要从我调用的方法中返回一些东西吗?还有其他方法吗?由于时间问题,任意超时似乎并不是一个好的解决方案。(注意,这段代码处于测试阶段,所以它的数据和变量名是假的)

4

1 回答 1

1

texttype函数中有第五个参数,它是在输入文本后调用的回调函数:

var doType = function(i) {
    var fullID = 'Div' + (i + 1); // Don't forget var!
    new Element('p', {
        'id': fullID
    }).inject($(document.body));
    texttype(fullID, lala[i], 100, 100, function() {
        doType(i + 1);
    });
}
doType(0);
于 2013-06-24T08:09:48.377 回答