我有以下代码:
var currentTemp = 0;
$.simpleWeather({
location: 'New York, New York',
woeid: '',
unit: 'f',
success: function(weather) {
currentTemp = weather.temp;
},
error: function(error) {
currentTemp = 150;
}
});
$('#degrees').text(currentTemp);
由于某种原因,变量 currentTemp 的值在 simpleWeather 函数内设置时,不会携带此函数。我该怎么办?
答案 0 :(得分:1)
$('#degrees').text(currentTemp)
不等待$ .simplerWeather启动success
处理程序。您应该将 {/ 1>}之后执行所需的任何代码移动到$.simplerWeather
处理程序(回调)
success