请协助。等待使用settimeout在javascript中重新运行之前完成的函数
我需要wait
完成一个操作,然后在javascript中再次执行它。这些操作可能会在不同的时间运行。不是一次全部。由于它们同时执行,所以我一次运行2个操作时遇到问题。
输出应使用settimeout
将文本附加到“textarea”中。它需要等待完成,然后开始在调用“arrayofrandomtext”数组的随机索引时键入下一个文本。后来上了“ProcessText(someint)”可能仍然是基于击键等
- 现有文本称为必须附加在0没有更换,而不是附加 即世界您好。别的东西....
var index=0;
var arrayofrandomtext = ["Hello World","something else", "other stuff"];
function ProcessText(someint){
//These may run together
next_letter(arrayofrandomtext[someint]);
//wait to complete and rerun it with other text
next_letter(arrayofrandomtext[someint]);
//later on if the user hits a key this may run only
next_letter(arrayofrandomtext[someint]);
}
function next_letter(text){
if (index <= text.length) {
someControl.value = text.substr(0, index++);
setTimeout(function() { next_letter(text); }, 50);
}
}
这是什么'someControl.value'。 –
input,textarea ... – user2185210