JavaScript execution issue

The following works correctly:

alert("start");
loadData(); // takes a while
alert("finished");

loadData () is a method that inserts large amounts of data into a table in the DOM and takes a few seconds.

This, however, does not work properly:

document.getElementById("mydiv").style.display = "block";
loadData(); // takes a while
document.getElementById("mydiv").style.display = "none";

Data is loaded into the table without displaying mydiv until the download is complete, and then mydiv is quickly displayed and disappears.

But this works as intended:

document.getElementById("mydiv").style.display = "block";
alert("start");
loadData(); // takes a while
alert("finish");
document.getElementById("mydiv").style.display = "none";

mydiv is displayed, a warning dialog is displayed, the data is loaded into the table, and then mydiv disappears, as expected.

Does anyone know why the second section of code above is not working correctly?

+3
source share
2 answers

, , LoadData - , , . u , div, LoadData.

:

function LoadData()
{
//Show Div here
//window.setTimeout(newFunc,100);
}

function newFunc()
{
 //Do data operations here
 //Hide Div
}
+4

javascript . :

void eventLoop () {
   struct event event;
   while(event = getEvent()){
        runJavascript(event);
        runBrowserCode();
        if(viewHasChanged) {
           redrawViewRegions();
        }
   }

}

, . javascript-, : . . gui , javascript, , , . javascript, - .

gui , , ... , gui! .

+3

Source: https://habr.com/ru/post/1728419/


All Articles