Basic Javascript loading message while js processing completes

前端 未结 3 1153
闹比i
闹比i 2021-01-13 04:43

Im sure this has been asked 1000 times before, basically all I want to do is change the content of an element of the page to display a loading message while my other javascr

3条回答
  •  有刺的猬
    2021-01-13 04:47

    What would be nice if you could do would be to call the showMessage function asynchronously. In other languages, you could do this with threads, and in HTML5 you can do this with workers, which are designed exactly for this sort of thing, but for right now you can most simply just use setTimeout, which makes the code in the first argument execute after a certain amount of time, allowing the current code to execute before it does.

    Change

       onclick="showMessage(); wasteTime();"
    

    to

       onclick="showMessage; setTimeout(wasteTime,5);"> 
    

提交回复
热议问题