开发者

Value resetting when a method is called within the onload

开发者 https://www.devze.com 2023-01-13 02:14 出处:网络
window.onload = init; function init(){ initializeEventHandlers(); getData(formatDate(new Date)); gotoDate(\'today\');
window.onload = init;

function init(){
   initializeEventHandlers();
   getData(formatDate(new Date));
   gotoDate('today');
}

//scripts that manage the UI for tracker.aspx
var dCurrentDate, sCur开发者_运维知识库rentDate, 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;

I load data from an XML which the sets some values. The probem I am facing is that when i set the values in the GetData method. The vars declared lose there value after the onload. What am i doing wrong and how can i make the values retain


Are the variables you're loading the data into defined in the global scope? From your getData() function, if you're setting the data to the steps, calories, and chipsAmount variables, they won't be accessible outside that function. You'll have to define those three variables outside the function so that they're in the global scope.

0

精彩评论

暂无评论...
验证码 换一张
取 消