using localStorage to store numbers

This question already has an answer here:

  • Storing Objects in HTML5 localStorage 25 answers

  • Local storage simply provides a way to store key value pairs. For example you can write something like localStorage.myName = 'Ali' And layer when you call

    localStorage.myName
    

    You'll get 'Ali'

    You can also store your object as is by saying

    localStorage.land = land
    

    But in this case your object will be stored as a string, so to retrieve it you can write something like

    var myObj = JSON.parse(localStorage.land) 
    

    Now myObj contains your land object.

    And also note to store objects as strings you have to use JSON.stringify(yourObject)

    链接地址: http://www.djcxy.com/p/27950.html

    上一篇: 带有发布配置的MySQL ++编译器警告

    下一篇: 使用localStorage来存储数字