zoukankan      html  css  js  c++  java
  • document.write 存在几个问题?应该注意

    • document.write (henceforth DW) does not work in XHTML  

    • XHTML 不支持
    • DW executed after the page has finished loading will overwrite the page, or write a new page, or not work

    • 如果在页面加载完后执行,会覆盖整个页面 或者 输出一个新的页面 或 不能工作
    • DW executes where encountered: it cannot inject at a given node point

    • 不能在指定节点注入
    • DW is effectively writing serialised text which is not the way the DOM works conceptually, and is an easy way to create bugs (.innerHTML has the same problem)

     document.write VS appendChild

     someScript.js

        console.log('2');
    

     index1.htm

    <script>
    console.log('1');
     var script = document.createElement('script');
     script.src = 'someScript.js';
     document.write(script.outerHTML);
    </script>
    <script>
    console.log('3');
    </script>
    

    index2.htm

    <script>
    console.log('1');
     var script = document.createElement('script');
     script.src = 'someScript.js';
     document.body.appendChild(script);
    </script>
    <script>
    console.log('3');
    </script>



    结果: index1.html 1、2、3 index2.html 1、3、2 ;
  • 相关阅读:
    mysql索引
    mysql锁机制
    mysql授权
    mysql执行计划
    mysql知识补遗
    求助:springboot调用存储过程并使用了pagehelper分页时报错com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
    java面试题1
    Yarn
    MapRudecer
    Hive数据倾斜和解决办法
  • 原文地址:https://www.cnblogs.com/czhyuwj/p/5531028.html
Copyright © 2011-2022 走看看