• Javascript中只能在 HTML 输出流中使用 document.write,在文档已加载后使用它(比如在函数中),会覆盖整个文档。


    意思就是说,初次加载时如果没有加载document.write,那么再次加载的时候回覆盖掉原来的内容,只显示新加载的内容。

     1 <!DOCTYPE html>
     2 <html>
     3   <head>
     4     <meta charset="UTF-8">
     5   </head>
     6 <body>
     7 
     8  <p>
     9    JavaScript 能够直接写入 HTML 输出流中:
    10  </p>
    11  <script>
    12   document.write("<h1>This is a heading</h1>");
    13   document.write("<p>This is a paragraph.</p>");
    14  </script>
    15 
    16  <p>
    17   您只能在 HTML 输出流中使用 <strong>document.write</strong>18   如果您在文档已加载后使用它(比如在函数中),会覆盖整个文档。
    19  </p>
    20 
    21  <button onclick="myFunction()">点击这里</button>
    22 
    23   <script>
    24   function myFunction()
    25   {
    26   document.write("调用了函数,文档被重写");
    27   }
    28   </script>
    29 
    30 </body>
    31  </html>
  • 相关阅读:
    要成功先发疯
    情绪ABC理论
    树立和提高威信法
    javaagent
    sonar 使用
    sonar 代码质量管理
    四大思维工具,SWOT、PDCA、DISC、时间管理
    HyperLogLog
    位数组
    git checkout .和git checkout -f的区别;git add . git add -u git add -A的区别
  • 原文地址:https://www.cnblogs.com/Alex1994/p/9790966.html
Copyright © 2020-2023  润新知