Javascript 未捕获错误:类型错误:对象#<;存储>;没有方法';把';

Javascript 未捕获错误:类型错误:对象#<;存储>;没有方法';把';,javascript,html,local-storage,Javascript,Html,Local Storage,我试图将一些信息放入HTML5 LocalStorage中,但是,在以下代码中出现错误“Object”没有方法“put”: window.localStorage.put('thing1', thing1); window.localStorage.put('thing2', thing2); window.localStorage.put('json', JSON.stringify(json)); 在脚本的开头,我检查了localstorage是否存在。我不需要在localStorage之

我试图将一些信息放入HTML5 LocalStorage中,但是,在以下代码中出现错误“Object”没有方法“put”:

window.localStorage.put('thing1', thing1);
window.localStorage.put('thing2', thing2);
window.localStorage.put('json', JSON.stringify(json));

在脚本的开头,我检查了localstorage是否存在。我不需要在localStorage之前指定窗口对象吗?

localStorage
使用
localStorage.setItem
,而不是
localStorage.put

试试。谢谢,我一发布问题就解决了这个问题:P