update global variable from a function in the javascript
问题 Here is the situation: I have one function which has local variable. I would like to assign that value to global variable and us it's value in another function. Here is the code: global_var = "abc"; function loadpages() { local_var = "xyz"; global_var= local_var; } function show_global_var_value() { alert(global_var); } I'm calling show_global_var_value() function in the HTML page but it shows the value = "xyz" not "abc" What am I doing wrong? 回答1: What you need to do apart from declaring