我的js
页面中有两个html
文件。如果第一个以:
(function($){
..
..
}(jQuery));
我可以在
var
中插入function($,varname)
,return
是它的值并在其他文件中使用它吗? 最佳答案
为此,您需要一个全局变量。您可以通过以下几种方式之一进行操作。假设我们需要将值“Bacon”发送到其他脚本。
(function($){
window.myScriptsExports = "Bacon";
}(jQuery));
// OR
var myScriptsExports = (function($){
// other code
return "Bacon";
// NO other code
}(jQuery));
// OR (not really recommended)
(function($){
// other code
$.myScriptsExports = "Bacon";
// other code
}(jQuery));