[英]Passing variables between multiple functions in jQuery?
所以我有一些看起來像這樣的代碼:
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.
因此,在調整瀏覽器大小並返回分辨率/屏幕大小並存儲在my_important_var_x
變量中后,調用checkmyresolutin()
之后,我需要將最新信息從該變量傳遞給function_abc();
my_important_var_x
功能...有人嗎?
編輯:
伙計們,有錯別字,但忽略了它們,我沒有復制粘貼我的.js,因為這最多需要400行,這只是一個例子 ,“邏輯”在這里很重要。
我只是需要以某種方式傳遞的內容enter code here
到function_abc()
后checkmyresolutin()
已被jQuery的運行resize function()
您有錯字:
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 ,並顯示令人討厭的警報,以顯示其工作正常。
我還制作了一個不同的版本 ,其中function_abc()在調整大小時自動調用,只是為了說明其工作原理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.