我有一个简单的降临日历,用户在特定日期打开门。我已经设置了一个jQuery cookie,但是我想让它在返回时记住用户上次会话,所以当他们返回时他们打开的门仍然打开 - 我已经设置了cookie但它没有保存数据,任何帮助不胜感激,谢谢!
开门 - 选择随机图像
$('.doors').click(function () {
if (today.getMonth() !== 11) {
return;
}
if ($(this).attr('id') <= 'dec' + (day + 10)) { // make it 11th Dec for testing
// Select Random Image
var doorImage = getRandomImage(calendarImg);
// Change background image of door that was clicked
$(this).css('background-image', doorImage);
return;
}
// Show image telling user to come back
$(this).css('background-image', 'url(/images/come_back.png)');
});
jQuery Cookie设置
// Create Cookie - Expires in 40 days
$.cookie('door_cookie', '1', { expires: 30, path: '/' });
// Read Cookie
$.cookie('door_cookie'); // => "the_value"
$.cookie('not_existing'); // => undefined
$.cookie(); // => { "the_cookie": "the_value", "...remaining": "cookies" }
// Returns true when cookie was found, false when no cookie was found...
//$.removeCookie('the_cookie', { path: '/' });
$.cookie.raw = true;
$.cookie.json = true;