动态加载JS(css)文件

时间:2022-12-20 08:06:56

<script language="javascript">
document.write("<script src='test.js'><\/script>");
</script>

第二种、动态改变已有script的src属性
<script src='' id="s1"></script>
<script language="javascript">
s1.src="test.js"
</script>

第三种、动态创建script元素:
<script>
var oHead = document.getElementsByTagName('HEAD').item(0);
var oScript= document.createElement("script");
oScript.type = "text/javascript";
oScript.src="test.js";
oHead.appendChild( oScript);
</script>