当我使用getScript时,定义的变量在javascript文件中不起作用 [英] Defined variables not working in javascript files when I use getScript
本文介绍了当我使用getScript时,定义的变量在javascript文件中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用 $。getScript
时,主javascript文件中的变量无法传递给包含的js文件。例如:
When I use $.getScript
the variables in the main javascript file cannot pass to included js file. For example:
var tVar = 'Hello World!';
$.getScript('js/setting.js', function() {
// My callback code
});
setting.js :
alert(tVar);
如何将变量传递给包含文件?
How can I pass variables to included file?
推荐答案
可以在你包含的js文件中使用一个函数,并将变量作为参数传递给该函数。
May be use a function inside your included js file and pass variable as arguement to that function.
这篇关于当我使用getScript时,定义的变量在javascript文件中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文