I'm trying to use the JQuery cookies library http://code.google.com/p/cookies/ But am not able to set key value 开发者_运维百科pairs within the cookie. I can't see how in the documentation, does anyone know how?
Thanks
Check out the JSON example in the link you referenced.
//JSON
var jimData = {id: 1, name: 'jim'};
$.cookies.set( 'userdata', jimData ); //A cookie by the name 'userdata' now exists with a serialized copy of jimData
var userData = $.cookies.get( 'userdata' ); //A variable named 'userData' now holds the unserialized object--should be identical to the variable 'jimData'
So, userData
should now have properties id
with value 1
and name
with value 'jim'
.
精彩评论