javascript 動態引用載入js/css檔案(遍曆文檔所有script,css節點);

來源:互聯網
上載者:User
function include(path,type,title){
 var s,i,t;
 if(arguments.length < 1){
  return ;
 }
 if(arguments.length == 1){
  type = "網頁特效";
 }
 switch(type.tolowercase()){
  case "css":
    t = document.getelementsbytagname("link");
    for(i=0;i<t.length;i++){
     if(t[i].href && t[i].href.indexof(path)!=-1){
      return;
     }
    }
    s=document.createelement("link");
    s.rel="alternate stylesheet";
    s.type="text/css";
    s.href=path;
    s.title=title;
    s.disabled=false;
    break;
  case "js":
  case "網頁特效":
  default:
    t = document.getelementsbytagname("script");
    for(i=0;i<t.length;i++){
     if(t[i].src && t[i].src.indexof(path)!=-1){
      return;
     }
    }
    s=document.createelement("script");
    s.type="text/javascript";
    s.src=path;
   break;
 }
 var h=document.getelementsbytagname("head")[0];
 h.appendchild(s);
}
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.