グローバル変数がa
あり、関数内で使用して値を割り当てています。関数の外でこの変数を使用すると、undefined
.
例えば。:
var a;
function my_func(){
a=5;
}
console.log(a); //outputs undefined, how do I get the value 5 here
undefined
の代わりに取得するのはなぜ5
ですか?
それは私の問題を解決しません。
var id;
function set_id(myid){
id=myid;
}
function get_id(){
return id;
}
$("#btn").click(function(){
$.post("....", function(data){ //data reurns a JSON
set_id(id); //success!!
}
}
$("#show").click(function()[
console.log(get_id()); //doesn't work, how do I get this workin.. Where am I going wrong
}