動態載入JS和CSS

毒逆天發表於2016-05-15

 

<script type=”text/javascript”>
$(function () {
var filename = `/assets/css/main.css`;
var fileref = document.createElement(“link”);
fileref.setAttribute(“rel”, “stylesheet”);
fileref.setAttribute(“type”, “text/css”);
fileref.setAttribute(“href”, filename);
document.getElementsByTagName(“head”)[0].appendChild(fileref);

 

var filescript = document.createElement(“script”);
filescript.type = “text/javascript”;
filescript.src = “/assets/js/main.js”;
document.getElementsByTagName(`body`)[0].appendChild(filescript);
});
</script>

作者:毒逆天
打賞:18i4JpL6g54yAPAefdtgqwRrZ43YJwAV5z
本文版權歸作者和部落格園共有。歡迎轉載,但必須保留此段宣告,且在文章頁面明顯位置給出原文連線!


相關文章