Storage:length 属性
Storage 接口的 length 只读属性返回存储在给定 Storage 对象中的数据项的数量。
值
存储在 Storage 对象中的项目数量。
示例
以下函数向当前域的本地存储添加三个数据项,然后返回存储中的项目数量
js
function populateStorage() {
localStorage.setItem("bgcolor", "yellow");
localStorage.setItem("font", "Helvetica");
localStorage.setItem("image", "cats.png");
return localStorage.length; // Should return 3
}
注意: 有关实际示例,请参阅我们的Web Storage 演示。
规范
| 规范 |
|---|
| HTML # dom-storage-length-dev |
浏览器兼容性
加载中…