Some questions and answers in the use of document.write in JS

Source: Internet
Author: User

  This article describes why you can overwrite the entire document if you call document.write after the page is loaded

I was a beginner, so I recorded it. The answer is seen in Baidu, so it is reproduced.     The following answers what is the entire document will be overwritten if the document.write is called after the page is loaded. The "HTML output" in the     hint refers to when the page is loaded.     Code as follows: <html>  <head></head>  <body>  <script type= "text/ JavaScript ">document.write" ("<p>Hello</p>");</script>  </body>  </html >    When the page is loaded, you will see Hello on the page. Viewing the source file is the code above.    -------------------------    But if the page is loaded and then used with document.write, the entire document will be overwritten.   Code as follows: <html>  <head></head>  <body>  <script type= "Text/javascript" > //When the mouse is clicked call document.write  Document.onclick = function () {  document.write ("<span> Javascript</span> "); };  </script>  </body>  </html>    Because the mouse action is executed after the page is loaded, the entire page is covered by <span>Javascript</span>. Now look at the source file and you will see only <span>Javascript</span>.  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.