0
我想使變量lat和loc全局,但它們始終爲零。在函數中定義的全局Javascript變量
var lat=0;
var loc=0;
navigator.geolocation.getCurrentPosition(function(position) {
lat = position.coords.latitude;
loc = position.coords.longitude;
});
alert(lat); // this eqals zero
函數內部的alert(lat)是什麼意思? –
[如何更改函數內部全局變量的值]的可能重複(http://stackoverflow.com/questions/10872006/how-to-change-value-of-global-variable-inside-of-function) –
@DavidRobinson Nopes。這不是這種情況! –