Getting jStorage to work
So I think jStorage is what I need to solve one of my problems. It needs JSON to be working with jQuery, so I've tried including it, but it doesn't seem to work. I have no idea what JSON is actually. Here's my code (jQuery is loaded higher). It doesn't even show the alert window.
<script type="text/javascript" src="jquery.json-2.2.min.js"&g开发者_开发百科t;</script>
<script type="text/javascript" src="jstorage.js"></script>
<script type="text/javascript">
$.jStorage.set(key, 'test');
value = $.jStorage.get(key);
alert("test"+value);
</script>
What could cause this?
$.jStorage.set('key', 'test');
value = $.jStorage.get('key');
alert("test"+value);
See http://www.jstorage.info/#usage: key needs to be string otherwise an exception is thrown
As i just discovered, the key/value set can be literally just about anything:
$.jStorage.set('matrix_nums', {"matrix":"$55\/HR","matnum":"25"},{"matrix":"225-17-01","matnum":"157"},{"matrix":"225-1708","matnum":"134"},{"matrix":"225-2708","matnum":"129"});
var _matrix = $.jStorage.get('matrix_num');
//test var for value
if(_matrix) {
$.each( _matrix, function(k,v) {
//... do stuff
} else {
load your JSON string manually and save it into local storage.
精彩评论