zoukankan      html  css  js  c++  java
  • 如何添加和删除本地存储中的数据?

    添加到本地存储的数据使用“键”和“值”。下面的示例代码显示了国家数据“India”添加的键值为“Key001”。

    localStorage.setItem(“Key001”,”India”);

    要检索本地存储的数据,我们需要使用“getItem”来提供键名。

    var country = localStorage.getItem(“Key001”);

    你还可以使用下面的代码存储JavaScript对象到本地存储。

    var country = {};
    country.name = “India”;
    country.code = “I001”;
    localStorage.setItem(“I001”, country);
    var country1 = localStorage.getItem(“I001”);

    如果你想用JSON格式存储,那么可以使用“JSON.stringify”函数,如下面所示的代码。

    localStorage.setItem(“I001”,JSON.stringify(country));
  • 相关阅读:
    python 代码片段8
    python 代码片段7
    python 代码片段6
    python 代码片段5
    python 代码片段4
    django 代码片段3
    python 代码片段2
    Redis事物
    Redis的java客户端jedis
    Redis五大数据类型
  • 原文地址:https://www.cnblogs.com/programb/p/13210312.html
Copyright © 2011-2022 走看看