zoukankan      html  css  js  c++  java
  • js document.write 总结

    hat document.write statements must be run before the page finishes loading. This means that they must be either in the body of the page or in functions called from the body of the page. So the following is acceptable:

    <script type="text/javascript">
    function w1() {
    document.write('hello world');
    }
    </script></head><body>
    <script type="text/javascript">
    w1();
    document.write('goodbye moon');
    </script>

    如果我们在html 的head内使用

     document.write("<h2>hello world</h2>");

    那么文本会出现在body的最开始的位置,后面才接着是原来的元素

    Any document.write statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page. This is almost certainly not what you intend to have happen. You should therefore avoid using document.write in situations such as this:

    <script type="text/javascript">
    function w1() {
    document.write('hello world'); // overwrite entire page
    }
    window.onload = w1;
    </script>

    会覆盖掉原来的网页而显示hello world.

    So you can only use document.write at best to write the original content of your page. It cannot be used to update the content of your page after that page has loaded.

  • 相关阅读:
    linux下svn命令大全
    php常用函数
    在centos上设置计划任务
    sphinx使用心得
    sphinx2.8.8的配置文件
    Mac使用
    sftp
    uwp应用在debug模式下运行正常,编译为release版本的时候抛出异常
    win10 uwp 读取resw资源文件
    dll被设置为用记事本打开的解决方法
  • 原文地址:https://www.cnblogs.com/youxin/p/2667611.html
Copyright © 2011-2022 走看看