[英]How do I get my page to display data that my functions process as they finish rather than when every function finishes
I have got 4 functions in my doLoad()
function that scan the document for spans and manipulate the data in them. 我的
doLoad()
函数中有4个函数, doLoad()
函数扫描文档的跨度并处理其中的数据。 these functions are very big and take a lot of time. 这些功能非常大,需要很多时间。 12 seconds.
12秒
The problem is, although these functions are independent of eachother, none of their work is presented until all 4 have finished execting. 问题是,尽管这些功能彼此独立,但在全部四个功能执行完毕之前,它们的工作将无法进行。
I want them to display the data as they finish excuting instead of displaying the data after all four have finish. 我希望他们在执行任务时显示数据,而不是在全部四个完成后显示数据。 How can I achieve that?
我该如何实现?
this is how my doLoad function looks like 这就是我的doLoad函数的样子
function doLoad(){
...
myFunction1();
myFunction2();
myFunction3();
myFunction4();
}
This should do the trick 这应该可以解决问题
function doLoad() {
setTimeout(myFunction1,1);
setTimeout(myFunction2,2);
setTimeout(myFunction3,3);
setTimeout(myFunction4,4);
}
By default, JS executes sequentially. 默认情况下,JS顺序执行。
If they are really independent you can use 如果他们真的独立,可以使用
function doLoad(){
...
setTimeout (myFunction1,5);
setTimeout (myFunction2,5);
setTimeout (myFunction3,5);
setTimeout (myFunction4,5);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.