我是一个重定向到自身的页面。(带有第二天和前一天的箭头)在 document.ready 页面显示新的一天。
这些日子存储在 localStorage 中,如下所示:
for(var i = 0;i<status.length;i++)
{
localStorage["Day" + i] = status[i].name;
}
我希望每次显示的默认日期是“Day0”,然后当用户单击下一个或上一个时显示前一天。
$(document).ready(function () {
$("#CurrentDay").empty();
$("#CurrentDay").append(GetCurrentDay());
});
function GetCurrentDay() {
localStorage["CurrentDay"] = localStorage["Day0"];
return localStorage["CurrentDay"];
}
我让箭头调用这些函数:
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"]];
}
}
我想知道当我在脚本开头用“0”初始化它时如何存储值“i”coz,每当调用页面时它都会返回到0,如果我让它没有值怎么能我知道我开始的地方吗?