如何在 HTML 中查找 localStorage 的大小?
htmljavascriptprogramming scripts
localStorage 用于在多个会话中保存信息。其最大大小为 5MB。
示例
您可以尝试运行以下代码片段来检查分配的大小 −
var sum = 0; // 循环获取大小 for(var i in localStorage) { var amount = (localStorage[i].length * 2) / 1024 / 1024; sum += amount; document.write( i + " = " + amount.toFixed(2) + " MB"); } document.write( "Total = " + sum.toFixed(2) + " MB");