how do I include .js link into another .js?

This question already has an answer here:

  • How do I include a JavaScript file in another JavaScript file? 50 answers

  • You cannot directly link a .js file from a .js file

    Check this: How do I include a JavaScript file in another JavaScript file?

    It clearly says what can you do to link a .js in a .js file


    Solution from about.com:

    In your testing.js file create this function:

    function addJavascript(jsname,pos) {
    var th = document.getElementsByTagName(pos)[0];
    var s = document.createElement('script');
    s.setAttribute('type','text/javascript');
    s.setAttribute('src',jsname);
    th.appendChild(s);
    }
    

    Later call the function using:

    addJavascript('http://code.jquery.com/jquery-latest.js','head');
    addJavascript('http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js','head');
    

    There are few other ways, but not all of them are compatible with all browsers.


    您只能在HTML页面中包含脚本文件,而不能在其他脚本文件中包含脚本文件

    链接地址: http://www.djcxy.com/p/7350.html

    上一篇: 如何在JS文件中使用外部(http)库

    下一篇: 我如何将.js链接包含到另一个.js中?