0

嗨,我在 javascript 中遇到问题。

当我尝试在控制台的 localStorage 中保存信息时,我遇到了未定义的错误“方法”推送。

<script type="text/javascript">                  

//localStorage.clear(); // Clears the hard drive (database)
var oUsers = {aIds:[], aNames:[]}; 

// Default            
if(localStorage.sUsers){
    console.log('Users already in memory');
    // Get the string with users from the database and
    // convert it into an object, so we can use it
    oUsers = JSON.parse(localStorage.sUsers); 
} 

function SaveUser(){
    // Take the text and make it an object                          
    oUsers.aIds.push(document.getElementById("TxtId").value);
    oUsers.aNames.push(document.getElementById("TxtName").value);               
    localStorage.sUsers = JSON.stringify(oUsers);
    console.log(localStorage.sUsers);                
}              

</script>  
4

0 回答 0