所以我有一些看起来像这样的代码:
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()
并返回分辨率/ sceensize并存储在my_important_var_x
变量中之后,我需要将该变量中的最新信息传递给{ {1}}功能......有人吗?
编辑:
伙计们,有拼写错误而忽略了它们,我没有复制粘贴我的.js,因为它需要多达400行,这只是一个 示例 , “逻辑”在这里很重要。
在jQuery function_abc();
enter code here
之后,我只需要以某种方式将function_abc()
的内容传递给checkmyresolutin()
答案 0 :(得分:0)
你有一个错字:
var my_important_var_x = 'init'; // my global variable for storing one very important piece of info. [screen size/resolution]
应该是
var my_important_Var_X = 'init'; // my global variable for storing one very important piece of info. [screen size/resolution]
看到这个JSFiddle,带有恼人的警报,以显示它正常工作。
我还使a different version在调整大小时自动调用function_abc(),以显示其工作原理。
在Javascript中查看变量范围的this discussion。