What does [removed]() do?

后端 未结 3 1155
孤城傲影
孤城傲影 2020-12-10 14:13

This is a very basic question. I have this script:

    

        
相关标签:
3条回答
  • 2020-12-10 14:50

    When the document is being read and parsed by the browser, if there's a script element that calls document.write, the output of document.write is inserted into the document at that point. Later, though, once the page is fully loaded, if you use document.write, it implicitly performs a document.open, which wipes out the page and starts writing a new one from scratch.

    More on MDN:

    • document.write
    • document.open

    In general, rather than using document.write to add content to a page, use the various DOM methods (either directly, or via a library like jQuery, YUI, Closure, or any of several others).

    0 讨论(0)
  • 2020-12-10 14:59

    When it is executed after the page has completed loading, it overwrites the entire content - one of the points raised in the answer to this question: Why is document.write considered a "bad practice"?

    0 讨论(0)
  • 2020-12-10 15:00

    document.write writes to the document stream, calling document.write on a closed (loaded) document automatically calls document.open, which will clear the document.

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