首页 新闻 会员 周边

localStorage的使用问题

0
悬赏园豆:5 [已关闭问题] 关闭于 2011-12-12 11:51

先说一下此段代码的主要功能:点击class=".pre"按钮时显示上一个楼宇,点击class=".next"是显示下一个楼宇,而localStorage则用来记载当前的楼宇。

问题:build顺序为:a,b,c,d,点击上一个(.pre)按钮时会按顺序实现,例如,如果当前是c,则点击上一个会依次显示b,a,所以上一个按钮是没有问题的。问题是下一个按钮(.next),如果当前是a,点击下一个就会直接跳到d,

现有如下代码:

nowStatID = 100000;
BuildingName = "中关村软件园A座";
boxid = "placeholder1";
var storage = window.localStorage;
if(storage.getItem("currentbuildingId")!= null)
{
nowStatID =storage.getItem("currentbuildingId");
BuildingName = storage.getItem("currentbuildingName");
}
$(document).ready(function(e) {
$("#buildingSummarize1 .next").click(function(){ //点击下一个
var build=eval(window.localStorage.getItem("buildings"));
for(var j=0; j<build.length; j++)
{
if(build[j].buildingID == nowStatID)
{
nowStatID = build[j+1].buildingID;
BuildingName = build[j+1].buildingName;
storage.setItem("currentbuildingId",nowStatID);
storage.setItem("currentbuildingName",BuildingName);
window.location.reload(); //(1)
}
}
});
$("#buildingSummarize1 .pre").click(function(){ //点击上一个
var build=eval(window.localStorage.getItem("buildings"));
for(var j=0; j<build.length; j++)
{
if(build[j].buildingID == nowStatID)
{
nowStatID = build[j-1].buildingID;
BuildingName = build[j-1].buildingName;
storage.setItem("currentbuildingId",nowStatID);
storage.setItem("currentbuildingName",BuildingName);
window.location.reload();
}
}
});
});

执行到(1)步骤时查看dom则发现localStorage存储的是a的下一个b,但是等到window.location.reload();之后显示的却是d,请问这是怎么回事呢?

 

 

 

 

呦菜的主页 呦菜 | 初学一级 | 园豆:2
提问于:2011-12-08 09:28
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册