zoukankan      html  css  js  c++  java
  • js 动态脚本

    当网站需求变大,脚本的需求也逐步变大。我们就不得不引入太多的JS 脚本而降低了
    整站的性能,所以就出现了动态脚本的概念,在适时的时候加载相应的脚本。
    比如:我们想在需要检测浏览器的时候,再引入检测文件。
    var flag = true; //设置true 再加载
    if (flag) {
      loadScript('browserdetect.js'); //设置加载的js
    }
    function loadScript(url) {
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.src = url;
      //document.head.appendChild(script); //document.head 表示<head>
      document.getElementsByTagName('head')[0].appendChild(script);
    }
    PS:document.head 调用,IE 不支持,会报错!

  • 相关阅读:
    撕衣服
    寒假作业1编程总结。
    C Traps and Pitfallss
    《彻底搞定C指针》文档整理
    C语言中内存分配 (转)
    ASCII
    ipad
    tour
    Diet
    第7章 输入与输出
  • 原文地址:https://www.cnblogs.com/andydao/p/3094894.html
Copyright © 2011-2022 走看看