jQuery Global Variable
问题 Can someone explain me why this doesn't work: $(function() { var damg = $(".hidden").val(); $("button").click(function() { alert(damg); }); }); jsFiddle: http://jsfiddle.net/raFnT/ Is it good to use global variables? I've also read that it is a slower option than typing it every time? To explain in detail: I have this: $("button").click(function() { alert(damg); }); and the damg is a value of the input: var damg = $(".hidden").val(); When you type something in the input and THEN press the