在JavaScript中推送方法

时间:2012-09-23 08:01:46

标签: javascript

嗨我在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>  

0 个答案:

没有答案