如何在 HTML 中查找 localStorage 的大小?
htmljavascriptprogramming scripts更新于 2024/8/18 12:28:17
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");
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

