首页 > 网站 > WEB开发 > 正文

JavaScript加载js和css文件方法

2024-04-27 15:07:23
字体:
来源:转载
供稿:网友
var ISDEBUG = true;    function loadSource(src){      this.src = src;      var srcs = this.src.split(",");      loadSource.PRototype.loadJS = loadSource.prototype.loadjs = function() {          var s = document.createElement('script');          s.src = this.src;          if(ISDEBUG) s.src = s.src +"?"+new Date().getTime();          s.async = true;          (document.body||document.head).appendChild(s);      };      loadSource.prototype.loadCSS = loadSource.prototype.loadcss = function() {          var c = document.createElement('link');          c.rel = 'stylesheet';          c.href = src;          if(ISDEBUG) c.href = c.href +"?"+new Date().getTime();          document.head.appendChild(c);      };      for(var i=0;i<srcs.length;i++){          this.src = srcs[i];          var type = src.split(".").pop();          if(this["load"+type]) this["load"+type]();      }  }
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表