【发布时间】:2010-08-27 02:37:04
【问题描述】:
window.onload = init;
function init(){
initializeEventHandlers();
getData(formatDate(new Date));
gotoDate('today');
}
//scripts that manage the UI for tracker.aspx
var dCurrentDate, sCurrentDate, sCurrentDayData, stepsVal, chipsVal, dayValue, dateValue, caloriesVal;
var fCurrentValue = 0;
var bAnimating, bSliding = false;
//scripts that manage the UI for tracker.aspx
var dCurrentDate, sCurrentDate, sCurrentDayData, stepsVal, chipsVal, dayValue, dateValue, caloriesVal;
var fCurrentValue = 0;
var bAnimating, bSliding = false;
getData(d)
{
steps = 5;
calories = 10;
chipsAmount = 3;
}
//I expect this to be 5+1, but it actually through an exception. I am wondering if its cause steps is not yet loaded. What can I do to make this actually 5 + 1.
steps + 1;
我从设置了一些值的 XML 加载数据。我面临的问题是,当我在 GetData 方法中设置值时。声明的变量在加载后失去了价值。我做错了什么以及如何使值保留
【问题讨论】:
-
您是在异步加载数据吗?如果是这样,则在您尝试设置它们时这些值可能不存在,因此您应该与脚本同步加载它。否则我不确定我是否完全理解你的问题。
-
是的,我正在同步加载
-
问题主要是我需要在onload时设置变量,以便其他函数可以使用它们
标签: javascript xml ajax