• 同步动态加载远程JS


    <html>
    <head>
    
    </head>
    <body>
    
    </body>
    </html>
    
    
    <script src="/lib/jquery.min.js"></script>
    
    <script>
    
    
        var a = 100;
    
        alert("执行前,a的值为:" + a);//100
        console.log(jQuery.fn.jquery);
    
        console.time("执行远程JS耗时");
        loadRemoteJs("/1.js");  //1.js 内容: a=20
        console.timeEnd("执行远程JS耗时");
    
        alert("执行后,a的值为:" + a);//20
        console.log(jQuery.fn.jquery);
    
    
    
    
    
    
        function loadRemoteJs(file) {
            $.ajax({
                url: file,
                method: 'GET',
                async: false
            }).success(function (result) {
                document.writeln("<script>" + result + "</script>");
            });
        }
    
    
    
        //https://www.cnblogs.com/jxlsomnus/p/4269945.html
    
    </script>
    
    
    <script>
        //(async function () {
    
        //    alert("执行前,a的值为:" + a);
    
        //    await $.getScript("/1.js");
    
        //    alert("执行后,a的值为:" + a);
    
        //})();
    </script>
    
    
    <script>
    
        //alert("执行前,a的值为:" + a);
    
        //loadjs("/1.js");//1.js会重设a的值
    
        //alert("执行后,a的值为:" + a);
    
    
    
        //function loadjs(file) {
        //    var head = $('head').remove('#loadscript');
        //    $("<scri" + "pt>" + "</scr" + "ipt>").attr({ src: file, type: 'text/javascript', id: 'loadscript' }).appendTo(head);
        //}
    
    </script>
    

      

  • 相关阅读:
    Merge Sorted Array
    Remove Duplicates from Sorted List
    Integer to Roman
    String to Integer (atoi)
    Valid Parentheses
    3Sum
    Remove Duplicates from Sorted Array
    Swap Nodes in Pairs
    得到一个Object的属性
    在WebGrid中做 批量删除操作
  • 原文地址:https://www.cnblogs.com/chinasoft/p/14081085.html
Copyright © 2020-2023  润新知