Globálne premenné Triky CSS

Anonim

Deklarovať premennú mimo funkcie…

var oneVariable; function setVariable()( oneVariable = "Variable set from within a function!"; ) function getVariable()( alert(oneVariable); // Outputs "Variable set from within a function!" )

Alebo ... pripojte ho k objektu okna

function setValue() ( window.myValue = "test"; ) function getValue() ( alert(window.myValue); // "test" (assuming setValue has run) )