0

I'm a page that redirects to itself. (With next day and previous day arrows) At document.ready the page displays the new day.

The days are stored in a localStorage like this :

for(var i = 0;i<status.length;i++)
  {
      localStorage["Day" + i] = status[i].name;
  }

I want the default day that shows every time is "Day0" then when the user clicks next or previous the other day is showed.

    $(document).ready(function () {
           $("#CurrentDay").empty();
           $("#CurrentDay").append(GetCurrentDay());
        });

   function GetCurrentDay() {
   localStorage["CurrentDay"] = localStorage["Day0"];
   return localStorage["CurrentDay"];
}

I made the arrows call these functions:

  function GoToNextDay() {
    if (i != localStorage["SchoolDays"]+1) {
        i = i + 1;
        localStorage["CurrentDay"] = localStorage["Day" + i];
    }
    else {
        localStorage["CurrentDay"] = localStorage["Day" + 0];
    }
}

 function GoToPrevDay() {
    if (i != 0) {
        i = i - 1;
        localStorage["CurrentDay"] = localStorage["Day" + i];
    }
    else {

    localStorage["CurrentDay"] = localStorage["Day" + localStorage["SelectedDaysNumber"]];
    }
}

I'm wondering how can I store the value "i" coz when I initialize it with "0" at the beginning of the script, it keeps returning to 0 whenever the page is called, and if I made it with no value how can I know the place I'm starting at ?

4

3 に答える 3