Is Javascript synchronous when manipulating the DOM?

前端 未结 1 1365
-上瘾入骨i
-上瘾入骨i 2020-12-20 15:55

I have a form with an input of type field. I have several radiobuttons, and depending on which of them I click, the value in the input type field will be updated. After that

相关标签:
1条回答
  • 2020-12-20 16:15

    As you said, just passing the value to the function would be preferred.

    But yes, setting the value of an input is synchronous; in what you describe, you will reliably get the updated value, cross-browser. Other DOM manipulations (inserting elements, removing them, moving them) are also synchronous, although the user may not see the result until your JavaScript code completes, letting the browser use the thread to repaint the display. (Although JavaScript is not inherently single-threaded, browsers use a single main UI thread to run your JavaScript code, and typically also use that thread to update the display.)

    0 讨论(0)
提交回复
热议问题