我在 localStorage 中存储了一些数据,我想动态输出这些数据(单击“之前”和“之后”箭头时)。我将页面重定向到自身并在文档准备好时显示当天的名称。
当我单击下一步时,天数会正确递增,但是当我之前单击时,天数不会正确递减,我尝试处理 (if counter =-1, counter= maxcounter) 的情况,但它不起作用.. .这是我试过的:
Javascript:
function GetCurrentDay() {
if (localStorage["CurrentDay"] == null || localStorage["CurrentDay"] == 'NaN' || localStorage["CurrentDay"]=="undefined") {
localStorage["Counter"]= 0;
i = localStorage["Counter"];
localStorage["CurrentDay"] = localStorage["Day" + i];
}
return localStorage["CurrentDay"];
}
function GoToNextDay() {
var d = GetCurrentDay();
i = localStorage["Counter"];
i = i*1 + 1;
localStorage["Counter"] = i;
if(i!= localStorage["SchoolDays"]+1){
localStorage["CurrentDay"] = localStorage["Day" + i];
}else{
localStorage["CurrentDay"] = localStorage["Day" + 0];
}
return true;
}
function GoToPrevDay() {
var d = GetCurrentDay();
i = localStorage["Counter"];
i = i*1 - 1;
localStorage["Counter"]=i;
if(i>0){
localStorage["CurrentDay"] = localStorage["Day" + i];
}else{
i=localStorage["SchoolDays"];
localStorage["Counter"]=i;
localStorage["CurrentDay"] = localStorage["Day" + i];
}
return true;
}
您对我该如何解决有任何想法吗?