Why alert() dialog shows first regardless of order in the code?

后端 未结 3 1783
感动是毒
感动是毒 2020-12-12 02:34

In the code sample below, I expect the text in div to change first.

But the text changes only after I click ok in the alert dialog.

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-12 03:14

    The browser do not update the DOM immediately. You can add a delay before calling the alert() function:

    setTimeout(function(){ alert(x) }, 10);
    

提交回复
热议问题