【发布时间】:2014-10-01 22:29:49
【问题描述】:
所以我有一些看起来像这样的代码:
var my_important_var_x = 'init'; // my global variable for storing one very important piece of info. [screen size/resolution]
function checkmyresolutin() {
// this tests the broswer/window resolution and print to the body [for css purposes]
var resolution_is = '768px';
my_important_var_x = resolution_is; // now the var contains the resolution
return my_important_Var_X;
}
checkmyresolutin(); // for getting the resolutoin on document ready.
$(window).resize(function(){
checkmyresolutin(); // this is the important part,every time the browser is resized i need to know ,certain function load/unload on certain resolutions.
});
function_abc(); // this is my problem,ill explain bellow,to keep this code block clean.
因此,在调整浏览器大小时调用checkmyresolutin() 并返回分辨率/屏幕大小并存储在my_important_var_x 变量中之后,我需要将该变量中的最新信息传递给function_abc(); 函数。 ..有人吗?
编辑:
伙计们,有错别字但忽略它们,我没有复制粘贴我的 .js,因为它最多需要 400 行,这只是一个 示例, “逻辑”在这里很重要。
在checkmyresolutin() 由jQuery resize function() 运行之后,我只需要以某种方式将enter code here 的内容传递给function_abc()
【问题讨论】:
-
我有点困惑。现在你不需要传递任何东西;该变量是全局变量。
-
也可以从
resize处理程序调用function_abc()吗? -
my_important_Var_X-vs-my_important_var_X? -
@TimVermaelen 错字...对不起
-
@Bergi 不行,必须这样。
标签: javascript jquery pass-by-reference