Localstorage无法正常工作

时间:2014-05-01 20:17:22

标签: javascript jquery html css

遇到麻烦,由于某种原因,如果它位于同一页面index.html,localstore var可以工作,但如果我把它移到我的site.js没有任何反应

var check = "Login as Admin";
  var names = [];
  var a = check;    
  names[0] = a;
  localStorage["names"] = JSON.stringify(names);
var storedNames = JSON.parse(localStorage["names"]);

这有效

var check = "Login as Admin";
  var names = [];
  var a = check;    
  names[0] = a;
  localStorage["names"] = JSON.stringify(names);
var storedNames = JSON.parse(localStorage["names"]);

if(storedNames == "Login as Admin"){
  window.location="events_edit.html";
}

0 个答案:

没有答案