2016-12-01 45 views
-1

Hej傢伙,我在FileZilla和Safari中使本地存儲工作有問題,它在谷歌瀏覽器(通常是:D)非常好用。按下按鈕時,它不會將任何內容保存到本地存儲中。你有一些提示,我應該添加或改變?謝謝本地存儲不工作在FileZilla和Safari

$(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 []; 
     } 
    } 
    }); 

回答

0

如果你想在localStorage保存嘗試這樣

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

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

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