JavaScript can only use document.write in the HTML output stream, which is used when the document is loaded (for example, in a function) and overwrites the entire document.
HTML output stream: The current data form is HTML-formatted data that is being exported, transmitted, or displayed, so it is called a "stream."
thinking: What is used in HTML output, and what is used after the document is loaded.
The reference code is as follows:
<! DOCTYPE html>
Example code execution to document.write to write to the page, the document load complete, but did not call the function, so will not execute document.write in the function, when the click button, triggered the event, is the document after the completion of the load is used document.write, will overwrite the original letter in the page Interest.
code written in JavaScript can only be executed through a html/xhtml document, one line at a line, and the document is actually loaded while loading and writing content to the screen with document.write, and when the load is complete, document closes. If you call document.write to write on the page again, the document will be rewritten.