動態(按需)載入js和css檔案

來源:互聯網
上載者:User
function $import(path,type,title){ var s,i; if(!type) type=path.substr(path.lastIndexOf(".")+1); if(type=="js"){     var ss=document.getElementsByTagName("script");     for(i=0;i<ss.length;i++){         if(ss[i].src && ss[i].src.indexOf(path)!=-1 || ss[i].title==title)return ss[i];     }     s=document.createElement("script");     s.type="text/javascript";     s.src=path;     if(title) s.title=title; }else if(type=="css"){     var ls=document.getElementsByTagName("link");     for(i=0;i<ls.length;i++){         if(ls[i].href && ls[i].href.indexOf(path)!=-1 || ls[i].title==title)return ls[i];     }     s=document.createElement("link");     s.rel="stylesheet";     s.type="text/css";     s.href=path;     if(title) s.title=title;     s.disabled=false; } else return; var head=document.getElementsByTagName("head")[0]; head.appendChild(s); return 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.