在HTML页面中加载js文件和css文件的方法

时间:2023-03-08 17:44:40
在HTML页面中加载js文件和css文件的方法

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);
}