低版本支持本地存贮store.js+json

来源:互联网 发布:windows抓包命令详解 编辑:程序博客网 时间:2024/06/09 15:34

在项目中难免要与低版本的浏览器打交道,本地存贮跟JSON的支持总是比jquery.cookie.js+json3.js(ie7--)或者local storage强大一些,这里介绍的是一款包含支持ie6全兼容的插件: store+json2 体积小,性价比高。可以使用下。

cdn:  http://cdn.bootcss.com/store.js/1.3.20/store+json2.min.js

官网: https://github.com/marcuswestin/store.js

store.js

store.js exposes a simple API for cross browser local storage

// Store 'marcus' at 'username'store.set('username', 'marcus')// Get 'username'store.get('username')// Remove 'username'store.remove('username')// Clear all keysstore.clear()// Store an object literal - store.js uses JSON.stringify under the hoodstore.set('user', { name: 'marcus', likes: 'javascript' })// Get the stored object - store.js uses JSON.parse under the hoodvar user = store.get('user')alert(user.name + ' likes ' + user.likes)// Get all stored valuesstore.getAll().user.name == 'marcus'// Loop over all stored valuesstore.forEach(function(key, val) {    console.log(key, '==', val)})
0 0