动态加载JS

1、直接document.write
<script language="javascript"> 
    document.write("<script src='test.js'><\/script>"); 
</script> 
2、动态改变已有script的src属性
<script src='' id="s1"></script> 
<script language="javascript"> 
    s1.src="test.js" 
</script> 
3、动态创建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> 

你可能感兴趣的:(js)