我试图在本地存储中设置一组变量,但函数没有运行,我试图获得值,但没有运气,如何保存本地存储中的字段?
function setPerson(){
var person = { 'name': getElementById('name'), 'photo': getElementById('photo')};
// Put the object into the storage
alert(person);
localStorage.setItem('person', JSON.stringify(person));
};
Run Code Online (Sandbox Code Playgroud)
HTML 在HTML中,我从字段中将值放入标记中并填充它们,但是当我尝试获取它们并保存它们时,没有任何事情发生......
我还尝试在那里输出固定值,然后显示警报,但是它只显示对象而不是值
var testObject = { 'one': 1, 'two': 2, 'three': 3 };
// Put the object into storage
localStorage.setItem('testObject', JSON.stringify(testObject));
// Retrieve the object from storage
var retrievedObject = localStorage.getItem('testObject');
alert('retrievedObject: ', JSON.parse(retrievedObject));;
Run Code Online (Sandbox Code Playgroud)