When does InnerHTML execute immediately?

假如想象 提交于 2019-12-02 12:11:41

Scripts and rendering are executed in a single thread. This means, that doThis will be finished before rendering starts. In the meanwhile you've set the inner HTML to 'b', and that will be the only result you'll see.

To fix this, you've to finish the first sub, and call intensiveOperation with a short delay, and make the final HTML update at the end of the second sub, like so:

Sub doThis
    statusinfo.InnerHTML = "a"
    Call window.setTimeout(GetRef("intensiveOperation"), 4)
End Sub

Sub intensiveOperation()
    'takes long
    statusinfo.InnerHTML = "b"
End Sub

Finishing doThis will free the thread. Notice, that setTimeout won't halt the execution, the whole sub is executed to the end. After that browser can render the page.

intensiveOperation is called at some point after the rendering is finished, not earlier than the given delay, but possibly much later, depending on tasks CPU is doing at the time.

The answer to the question in the header of the question is basically: never.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!