localStorage的使用方法以及一些注意事项
程序员文章站
2024-02-28 08:46:22
...
基本使用方法:
[Storage.key()
](https://developer.mozilla.org/en-US/docs/Web/API/Storage/key)
//When passed a number n, this method will return the name of the nth key in the storage.
[Storage.getItem()
](https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem)
//When passed a key name, will return that key's value.
[Storage.setItem()
](https://developer.mozilla.org/en-US/docs/Web/API/Storage/setItem)
//When passed a key name and value, will add that key to the storage, or update that key's value if it already exists.
[Storage.removeItem()
](https://developer.mozilla.org/en-US/docs/Web/API/Storage/removeItem)
//When passed a key name, will remove that key from the storage.
[Storage.clear()
](https://developer.mozilla.org/en-US/docs/Web/API/Storage/clear)
//When invoked, will empty all keys out of the storage.
其他:
- 只能存储字符串
- chrome 56下, 极限大小是5M左右.
- Safari无痕模式下设置localStorage会抛出异常.
上一篇: Android中使用Matrix控制图形变换和制作倒影效果的方法
下一篇: java应用领域分析