本地存储不在filezilla和safari中工作

时间:2016-12-01 12:05:47

标签: javascript jquery local-storage

Hej伙计们,我在FileZilla和Safari中使Local Storage工作有问题,它在Google Chrome中运行得非常好(通常是:D)。按下按钮时,它不会将任何内容保存到本地存储。你有什么提示我应该添加或改变?谢谢

$( document ).ready(function() {
    $(".logInAsAdmin").click(function(){
            var jStudent = {};
            jStudent.userSingUpNameLS = "Admin";
            jStudent.userLastNameLS= "Tivoli2016";
            console.log(jStudent);
            var sStudentsFromLocalStorage = localStorage.sajStudents;
            console.log(sStudentsFromLocalStorage);
            var aStudents = getDataFromLocalStorageAsObject();
            aStudents.push(jStudent);
                // console.log(aStudents);
                // convert the array into a string
                var sFinal = JSON.stringify(aStudents);
                console.log(sFinal);
                localStorage.sajStudents = sFinal;
                $(".myModal").modal('show');
                //e.preventDefault();
              });
    function getDataFromLocalStorageAsObject(){
      try{
        return JSON.parse(localStorage.sajStudents);
      }
      catch(e){
        return [];
      }
    }
  });

1 个答案:

答案 0 :(得分:0)

如果你想保存在localStorage,请尝试这样

//Add
localStorage.setItem("Key", Value)

//Get
localStorage.getItem("Key");

//Remove
localStorage.removeItem("Key");