How to add an js in a function when call?
<pre><code>(function() {
    var jQuery;
    if (window.jQuery === undefined || window.jQuery.fn.jquery !== "1.7.1") {
        var script_tag = document.createElement("script");
        script_tag.setAttribute("type","text/javascript");
        script_tag.setAttribute("src",
            "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js");
        var script_tag2 = document.createElement("script");
        script_tag2.setAttribute("type","text/javascript");
        script_tag2.setAttribute("src",
            "test.js");
        if (script_tag.readyState) {
          script_tag.onreadystatechange = function () { // For old versions of IE
              if (this.readyState == "complete" || this.readyState == "loaded") {
                  scriptLoadHandler();
              }
          };
        } else {
          script_tag.onload = scriptLoadHandler;
          script_tag2.onload = scriptLoadHandler;
        }
        (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
    } else {
        jQuery = window.jQuery;
        main();
    }

    function scriptLoadHandler() {
        jQuery = window.jQuery.noConflict(true);
        main();
    }

    function main() { 
        jQuery(document).ready(function($) {
            // code here ...
        });
    }
})();
</code></pre>

<p>When I run code is result in firebug is error can't load library jquery.min.js and test.js</p>
