在HTML頁面中加載js文件和css文件的方法
阿新 • • 發佈:2018-01-20
logs ext mar 頁面 document 文件 class link child
1.在HTML頁面加載js文件的方法:
function loadScriptFile(filePath){
var script = document.createElement("script");
script.type = "text/javascript";
script.src = filePath;
document.head.appendChild(script);
}
2.在HTML頁面加載css文件的方法:
function loadCsstFile(filePath){ var link = document.createElement("link"); link.type = "text/css"; link.rel = "stylesheet"; link.href = "filePath"; document.head.appendChild(link); //document.getElementsByTagName("head")[0].appendChild(link); }
在HTML頁面中加載js文件和css文件的方法