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 |
瀏覽器相容性
載入中…