如何将变量传递到 jquery.getScript



>我一直在看jquery网站,但我认为我不太了解这一点,因为我没有看到任何console.logs。

$(document).ready(function(){
    var a=[1,2,3];
    var b='foo';
    var c={'bar':'baz'};
    $.getScript('script.js',function(a,b,c){
        console.log('how can i see a='+a+', b='+b+' and c='+c+' inside here?');
        });
    });

脚本是在全局上下文中执行的,所以不要传递参数(它们正在隐藏脚本定义的参数):

$.getScript('script.js',function(){
    // use a, b and c here
    console.log(a);
});

最新更新