rt~

解决方案 »

  1.   

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

  2.   

    jQuery.getScript("http://dev.jquery.com/view/trunk/plugins/color/jquery.color.js", function(){
      ……
    });
    加载外部脚本
      

  3.   

    你只用 把   被包含的js文件
    <script src="../被包含文件jsURL" type="text/javascript"></script>
    在 你引用的这个js文件前面,这样你就可以在 你的js中使用 被包含js的所有内容
      

  4.   

    一直在寻找如<include>之类的方法,原来在这里
      

  5.   

    可以考虑Dojo,它类似于java的包引入
      

  6.   

    尽量少用 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); 
    };