日期:2014-05-16  浏览次数:20349 次

如何在一个JS文件中包含另一个JS文件呢?
rt~

------解决方案--------------------
<script>
function loadJs(name) {
document.write('<script src="'+name+'" type="text/javascript"></script>');
}
</script>

这样子的吗??
------解决方案--------------------
探讨
<script>
function loadJs(name) {
document.write('<script src="'+name+'" type="text/javascript"></script>');
}
</script>

这样子的吗??

------解决方案--------------------
jQuery.getScript("http://dev.jquery.com/view/trunk/plugins/color/jquery.color.js", function(){
……
});
加载外部脚本
------解决方案--------------------
你只用 把 被包含的js文件
<script src="../被包含文件jsURL" type="text/javascript"></script>
在 你引用的这个js文件前面,这样你就可以在 你的js中使用 被包含js的所有内容
------解决方案--------------------
document.write
------解决方案--------------------
尽量少用 document.write


 // 动态导入js
function include(src,encoding,fun) 

var s = document.createElement('script');
s.type='text/javascript';
s.charset=encoding; //'gb2312';
s.src = src;
var tags =document.getElementsByTagName('head');
if(typeof(fun)=='function'){
if( document.all ){
s.onreadystatechange = function(){
if(/(complete|loaded)/.test(this.readyState)){
fun(); s.onreadystatechange = null; s.parentNode.removeChild(s); 
}};
}else{
s.onload = function(){ fun(); s.onload = null; s.parentNode.removeChild(s); };
}

tags[0].appendChild(s); 
};