更新时间:2023-12-02 23:35:58
不要依赖的的localStorage
键的顺序。您可以通过所有可用的钥匙放在的localStorage
重复使用的localStorage [N]
,但这指的是关键(串)可与使用的localStorage [str_key]
或 localStorage.getItem(str_key)
。
Don't rely on the order of localStorage
keys. You can iterate through all available keys on localStorage
using localStorage[n]
, but that refers to a key (string) which can be used with localStorage[str_key]
or localStorage.getItem(str_key)
.
在你的情况,你迷茫的的localStorage
键的名称与分配给该项目的名称索引。因此,不使用关键指标,但你的价值的关键:
In your case, you've confused the index of the localStorage
key names with the name you assigned to the item. Therefore, don't use the key index, but your value key:
for (i=0;i<localStorage.length;i++)
{
var key = localStorage.key(i);
if(key != null)
{
var value = localStorage.getItem(key);
$("#"+key).next(".dynamicList").empty();
$("#"+key).next(".dynamicList").append(value);
}
}