dpps0715 2016-04-30 12:05
浏览 30
已采纳

从Javascript里面调用Javascript

Currently I am using three external JS file.

<script src="https://code.jquery.com/jquery-2.0.0.min.js" type="text/javascript"></script> 
<script src="http://example.com/jquery.cookie.js" type="text/javascript"></script>
<script src="http://example.com/js.cookie.js" type="text/javascript"></script> 

I like to make all three JS file in one.

Do it possible. i create aio.js and inside aio.js

src="https://code.jquery.com/jquery-2.0.0.min.js";
src="http://example.com/jquery.cookie.js";
src="http://example.com/js.cookie.js";

And then i will add

<script src="http://example.com/aio.js" type="text/javascript"></script>

So the Single File aio.js call all the 3 files.

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongsigan2044 2016-04-30 12:10
    关注

    Here is the Live example..

    var element1 = document.createElement("script");
    element1.src = "https://code.jquery.com/jquery-2.0.0.min.js";
    document.body.appendChild(element1);
    console.log(element1)

    For you :

    Put this code in your http://example.com/aio.js file

    window.onload = function() {
       var element1 = document.createElement("script");
       element1.src = "https://code.jquery.com/jquery-2.0.0.min.js";
       document.body.appendChild(element1);
    
       var element2 = document.createElement("script");
       element2.src = "http://example.com/jquery.cookie.js";
       document.body.appendChild(element2);
    
       var element3 = document.createElement("script");
       element3.src = "http://example.com/js.cookie.js";
       document.body.appendChild(element3);
    }
    

    And in your html file..

    <script src="http://example.com/aio.js" type="text/javascript"></script>
    
    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用