简体   繁体   English

如何使页面显示函数完成时而不是每个函数完成时处理的数据

[英]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.

相关问题 如何使我的函数特定于数组中的单个对象,而不是全局影响它们? - How do I make my functions specific to individual objects in an array, rather than globally effecting them all? 使用http访问我的Facebook iframe页面时,如何获得模态而不是弹出窗口? - How can I get a Modal rather than a pop up when using http to access my facebook iframe page? 当页面完成加载时,我如何使我的模态 jquery 加载 - how do i make my modal jquery load when page finishes loading 如何检测文件被拖动而不是我页面上的可拖动元素? - How do I detect a file is being dragged rather than a draggable element on my page? 如何获取要在弹出窗口中处理的表数据 - How do I get data of my table to process in a popup 在另一个函数完成读取输入的每个字母后,如何让 setInterval 函数终止? - How do I get a setInterval function to terminate after another function finishes off reading every letter of the input? 如何根据URL数据显示数据? - How do I get my data to display based on URL data? 当我将显示更改为“无”和“阻止”时,我的标题会重新定位,而不是消失并重新出现在原来的位置 - When I change display to "none" and "block", my title repositions rather than disappearing and reappearing where it originally was 当内部HTML由Javascript函数生成时,如何获取页面一部分的innerHTML? - How do I get the innerHTML of a part of my page when that inner HTML is generated by a Javascript function? 我如何让我的 function 在我的桌子的每一行上工作? - How do i get my function to work on every row of my table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM