<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>