Save Javascript objects in sessionStorage

后端 未结 9 720
抹茶落季
抹茶落季 2020-12-02 05:14

SessionStorage and LocalStorage allows to save key/value pairs in a web browser. The value must be a string, and save js objects is not trivial.

var user = {         


        
9条回答
  •  既然无缘
    2020-12-02 05:42

    Could you not 'stringify' your object...then use sessionStorage.setItem() to store that string representation of your object...then when you need it sessionStorage.getItem() and then use $.parseJSON() to get it back out?

    Working example http://jsfiddle.net/pKXMa/

提交回复
热议问题